Skip to main content

Home/ Python Programming/ Group items tagged imported

Rss Feed Group items tagged

reckoner reckoner

Plotting NaNs in Matplotlib (matplotlib-users) - 0 views

  • Your example works as you describe on recent matplotlib versions. I suspect you are using an old one. The preferred way of handling missing points in numpy, and therefore in matplotlib and pylab, however, is via masked arrays.import pylabimport numpy as npfrom numpy import maa = [1,2,3,4,5]b = np.array([6,2,np.nan,1,9])bm = ma.masked_where(np.isnan(b), b)pylab.plot(a,bm)pylab.show()There are many other examples of masked array use in the examples directory of the matplotlib distribution.EricFernando Abilleira wrote:> Dear sourceforge community,> > I come from a Matlab environment so I am used to plotting matrices that > contain NaN elements. This is very useful because in some cases one > doesn't have data for the entire matrix. If one tries plotting the data, > the NaN elements won't be plotted.
Jac Londe

JSON Developer's Guide for the Google Feed API - 0 views

  • Using Python The following code snippet shows how to make a request to the Google Feed API using Python. This sample assumes Python 2.4 or higher. You may need to download and install simplejson. import urllib2import simplejsonurl = ('https://ajax.googleapis.com/ajax/services/feed/find?' +       'v=1.0&q=Official%20Google%20Blog&userip=INSERT-USER-IP')request = urllib2.Request(url, None, {'Referer': /* Enter the URL of your site here */})response = urllib2.urlopen(request)# Process the JSON string.results = simplejson.load(response)# now have some fun with the results...
  •  
    JSON Developer's Guide for the Google Feed API - Google Feed API - Google Developers
reckoner reckoner

Re: Python in Excel - 0 views

  • You can use Microsoft Script Control. If you have the win32 extensions of python, you can use python in place of vb in this control -open the VBA script editor - In menus/Tools/References add Microsoft Script Control -Make a new module and declare a new MsScriptControl.ScriptControl Global sc as new MsScriptControl.ScriptControl -Initialize the language attibute with python - Note that you and users of your document must have python and its win32 extensions installed. Activestate python distribustion include it. You can put sc.language="python" in the routine Workbook_Open() Now you can import python modules using ExecuteStatement method of the control in vba and have results from python functions with eval method. One interesting thing is that you can pass an object to the control with AddObject method and have python manipulate it. And so on..
  • Global sc As New MSScriptControl.ScriptControl Public Function os_getcwd() sc.Language = "python" sc.ExecuteStatement ("import os") os_getcwd = sc.Eval("os.getcwd()") End Function With this you can set your Excel formula to =os_getcwd() For me it returns "C:\Documents and Settings\Administrator\My Documents", which I needed to know at the time so I didn't have to screw around with the ever annoying pythonpath. You can put the first two lines of the function in the Workbook_Open hook, but I don't know where that is. I hope to use more Python in Excel soon. Hmm, actually, I suppose you can put those first two lines of the function after the Global declaration as well. I know just about zero VBScript and didn't get a chance to do anything else beyond proof of concept yet. I figured I would write something dynamic which allowed more transparent access to Python, maybe allowing formula like =py("os.getcwd()"), etc.
reckoner reckoner

XGraph plot dot showing multiple edges - networkx-discuss | Google Groups - 0 views

  • For example edge labels can be added using matplotlib "text" objects like this: import networkx as nx import pylab as plot K=nx.XGraph(name="Konigsberg", multiedges=True, selfloops=False) K.add_edges_from([("A","B","Honey Bridge"),     ("A","B","Blacksmith's Bridge"),     ("A","C","Green Bridge"),     ("A","C","Connecting Bridge"),     ("A","D","Merchant's Bridge"),     ("C","D","High Bridge"),     ("B","D","Wooden Bridge")]) pos=nx.spring_layout(K) nx.draw_nx(K,pos) xa,ya=pos['A'] xb,yb=pos['B'] plot.text((xa+xb)/2,(ya+yb)/2,"Blacksmith's Bridge") plot.show() With a little work you can get the label rotated and exactly how you want it positioned.  You can also set the node positions directly in the "pos" dictionary above.
reckoner reckoner

How to get currently active window on Win32? - 0 views

  • On Sat, 15 Dec 2001 17:53:49 -0800 (PST), David Brady <daves_spam_dodging_account at yahoo.com> wrote : >More win32all questions... is it possible to get the >handle of the window that currently has the focus? >win32gui.GetActiveWindow() fails because I'm looking >for a window outside the process of my Python script. E:\>python ActivePython 2.1.1, build 212 (ActiveState) Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> import win32gui >>> import time >>> for x in range(10): ... time.sleep(1) ... print x, win32gui.GetWindowText(win32gui.GetForegroundWindow()) ... 0 cmd - python 1 cmd - python 2 (Untitled) * SciTE 3 (Untitled) * SciTE 4 ActivePython Documentation 5 ActivePython Documentation 6 PythonWin 7 PythonWin 8 PythonWin
reckoner reckoner

Pypar -- parallel programming - 0 views

  • Pypar does not require the Python interpreter to be modified or recompiled: Parallel python programs use the standard Python and need merely import the pypar module. This means for example that you can upgrade Python independently of your parallel codes.
  • Pypar is an efficient but easy-to-use module that allows programs/scripts written in the Python programming language to run in parallel on multiple processors and communicate using message passing. Pypar provides bindings to an important subset of the message passing interface standard MPI. Other Python MPI bindings available from other developers include: PyMPI, Scientific Python and pythonMPI.
reckoner reckoner

pyscripter - Using matplotlib with PyScripter - 0 views

  • interpreter:>>>import matplotlib>>>matplotlib.interactive(True)>>>matplotlib.use("WXAgg")>>>from matplotlib.pylab import *>>>plot([1,2,3])>>>xlabel('time (s)') 
reckoner reckoner

ASPN : Python Cookbook : SendKeys from the Windows Script Host (WSH) COM - 0 views

  • import win32api import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.Run("calc") win32api.Sleep(100) shell.AppActivate("Calculator") win32api.Sleep(100) shell.SendKeys("1{+}") win32api.Sleep(500) shell.SendKeys("2") win32api.Sleep(500) shell.SendKeys("~") # ~ is the same as {ENTER} win32api.Sleep(500) shell.SendKeys("*3") win32api.Sleep(500) shell.SendKeys("~") win32api.Sleep(2500)
Jac Londe

Eli Bendersky's website » Python metaclasses by example - 12 views

    • Mauro De Giorgi
       
      Start read from here
  • Study and understand this example and you’ll grasp most of what one needs to know about writing metaclasses.
  • To control the creation and initialization of the class in the metaclass, you can implement the metaclass’s __new__ method and/or __init__ constructor [6]. Most real-life metaclasses will probably override just one of them. __new__ should be implemented when you want to control the creation of a new object (class in our case), and __init__ should be implemented when you want to control the initialization of the new object after it has been created.
  • ...3 more annotations...
  • It’s important to note here that these print-outs are actually done at class creation time, i.e. when the module containing the class is being imported for the first time. Keep this detail in mind for later.
  • So when the call to MyMeta is done above, what happens under the hood is this:
  • Python metaclasses by example
luke jenning

Learn the basics of Python and start coding today! - 0 views

  •  
    The Python programming language is a high level programming language that is used in a wide spectrum of applications -- from web design and game programming to scientific research.
mesbah095

Guest Post Online - 0 views

  •  
    Article Writing & Guestpost You Can Join this Site for Your Article & guest post, Just Easy way to join this site & total free Article site. This site article post to totally free Way. Guest Post & Article Post live to Life time only for Current & this time new User. http://guestpostonline.com
  •  
    Article Writing & Guestpost You Can Join this Site for Your Article & guest post, Just Easy way to join this site & total free Article site. This site article post to totally free Way. Guest Post & Article Post live to Life time only for Current & this time new User. http://guestpostonline.com
Learn Python

Introduction To Learn Python Tutorial - 0 views

  •  
    Learn how to program with Python the right way
reckoner reckoner

psychotic - accelerate python code - 0 views

  • sychotic is an innovative optimizing compiler for Python code. It has unique features, the most important of which is that it breaks through the ConstantTimeBarrier. It is very easy to use and has an interface similar to that of the popular Psyco project. Below, you can see a usage example. You can also learn about HowItWorks, the ProjectHistory and KnownIssues. You can also browse the easy-to-understand source especially the alysis.py analyzer module and the dingo.py runtime bootstrap. There is an introductory screencast available (less than 5 minutes long). Usage
reckoner reckoner

Applying sympy expressions on numpy arrays - sympy | Google Groups - 0 views

  • If I have:     from sympy import Symbol, Integrate     x = Symbol('x')     f = x**2 + x     g = Integrate(f, x) how can I apply g to a numpy array? In other words, how can I "numpify" the g expression, injecting in it x = numpy.linspace(1, 9, 9)? What would be even nicer would be to be able to retrieve a lambda using numpy functions for g as a function of x (that way I don't have the overhead of numpifying it each time I want to apply it to an array).
reckoner reckoner

[IPython-user] ipython1 and farm tasking - 0 views

  • [IPython-user] ipython1 and farm tasking Brian Granger ellisonbg.net@gmail.... Wed Feb 27 16:29:03 CST 2008 Previous message: [IPython-user] ipython1 and farm tasking Next message: [IPython-user] yet another leopard/readline question Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Alex, First, I would suggest updating your ipython1 install from our svn repository. We are about to push out a major new version and the documentation is _much_ better. Also, there are many new features that will hopefully help you. Here is a simple example (using the latest svn of ipython1): In [1]: from ipython1.kernel import client In [2]: mec = client.MultiEngineClient(('127.0.0.1',10105)) In [3]: tc = client.TaskClient(('127.0.0.1',10113)) In [4]: def fold_package(x): ...: return 2.0*x ...: In [5]: mec.push_function(dict(fold_package=fold_package)) Out[5]: [None, None, None, None] In [6]: tasks = [client.Task("y=fold_package(x)",push={'x':x},pull=('y',)) for x in range(128)] In [7]: task_ids = [tc.run(t) for t in tasks] In [8]: tc.barrier(task_ids) In [9]: task_results = [tc.get_task_result(tid) for tid in task_ids] In [10]: results = [tr.ns.y for tr in task_results] In [11]: print results [0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0, 34.0, 36.0, 38.0, 40.0, 42.0, 44.0, 46.0, 48.0, 50.0, 52.0, 54.0, 56.0, 58.0, 60.0, 62.0, 64.0, 66.0, 68.0, 70.0, 72.0, 74.0, 76.0, 78.0, 80.0, 82.0, 84.0, 86.0, 88.0, 90.0, 92.0, 94.0, 96.0, 98.0, 100.0, 102.0, 104.0, 106.0, 108.0, 110.0, 112.0, 114.0, 116.0, 118.0, 120.0, 122.0, 124.0, 126.0, 128.0, 130.0, 132.0, 134.0, 136.0, 138.0, 140.0, 142.0, 144.0, 146.0, 148.0, 150.0, 152.0, 154.0, 156.0, 158.0, 160.0, 162.0, 164.0, 166.0, 168.0, 170.0, 172.0, 174.0, 176.0, 178.0, 180.0, 182.0, 184.0, 186.0, 188.0, 190.0, 192.0, 194.0, 196.0, 198.0, 200.0, 202.0, 204.0, 206.0, 208.0, 210.0, 212.0, 214.0, 216.0, 218.0, 220.0, 222.0, 224.0, 226.0, 228.0, 230.0, 232.0, 234.0, 236.0, 238.0, 240.0, 242.0, 244.0, 246.0, 248.0, 250.0, 252.0, 254.0] Or if you don't need load balancing: # This sends the fold_package function for you! results = mec.map(fold_package, range(128)) Let us know if you run into other problems. Cheers, Brian
reckoner reckoner

non-interactive ipython for script - 0 views

  • Note that it's more rebust to run methods on the public IPython api.I.e. do ip = ipshell.api and then ip.magic('px import os')You can explore the api interactively by playing with _ip object.
  •  
    noninteractive ipython for regular python script
reckoner reckoner

[IPython-user] setting breakpoints in code - 0 views

  • Robin, Give this a try: from IPython.Debugger import Tracer; debugger = Tracer() debugger() #add this line where you want to break barr
1 - 20 of 80 Next › Last »
Showing 20 items per page