How to schedule execution of code?
Suppose that I have some Python code (vers. 2.6) that has been converted into an *.exe file and can be executed on a Windows (Vista or 7) platform. What can one do to have this *.exe executed at a set of specific times each day? In addition, if a day is missed (e.g. computer on which it resides goes down), then it will be executed the next time the computer is successfully started up. It might be useful to know that the purpose of this code is to collect data from a set of RSS feeds. Any suggestions would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to schedule execution of code?
On Tue, Mar 15, 2011 at 3:16 PM, Virgil Stokes wrote: > Suppose that I have some Python code (vers. 2.6) that has been converted > into an *.exe file and can be executed on a Windows (Vista or 7) platform. > What can one do to have this *.exe executed at a set of specific times each > day? In addition, if a day is missed (e.g. computer on which it resides goes > down), then it will be executed the next time the computer is successfully > started up. > Can't the windows scheduler handle this ? there is also pycron for windows, if you are so inclined. > > It might be useful to know that the purpose of this code is to collect data > from a set of RSS feeds. > > Any suggestions would be appreciated. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Low Kian Seong Senior Software Manager Logistics Consulting Asia M: +6 012 3736874 • T: +60 3 7729 9386 • F: +60 3 7729 7386 www.logisticsconsulting.asia China • India • Indonesia • Malaysia • Philippines • Singapore • Thailand • Vietnam -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido rethinking removal of cmp from sort method
Ian Kelly writes: > I would think that you can sort them with key as long as none of the > sequences are equal (which would result in an infinite loop using > either method). Why not this? Yes you can do something like that, but look how ugly it is compared with using cmp. -- http://mail.python.org/mailman/listinfo/python-list
newbie question (for loop)
BB, I am getting error on the following syntax while running in Ipython and spyder and I failed to figure out why for i in range(len(list)) Error for i in range(len(list)) ^ SyntaxError: invalid syntax where list is a list defined as a collection of words and it is OK prints fine. Kindly advise. Cheers Sachin Sachin Kumar Sharma Senior Geomodeler -- http://mail.python.org/mailman/listinfo/python-list
alphanumeric list
Hi all, I would like to put an alphanumeric string like this one EE472A86441AF2E629DE360 in a list, then iterate inside the entire string lenght and change each digit with a random digit. Do u have some suggestion? thanks a lot -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question (for loop)
On Tue, Mar 15, 2011 at 1:01 AM, Sachin Kumar Sharma wrote:
> I am getting error on the following syntax while running in Ipython and
> spyder and I failed to figure out why
>
> for i in range(len(list))
> ^
> SyntaxError: invalid syntax
You forgot the required colon (":"). It should be
for i in range(len(list)): # note trailing colon
Cheers,
Chris
--
"BB"?
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
On Tue, Mar 15, 2011 at 1:10 AM, yqyq22 wrote: > Hi all, > I would like to put an alphanumeric string like this one > EE472A86441AF2E629DE360 in a list, then iterate inside the entire > string lenght and change each digit with a random digit. > Do u have some suggestion? thanks a lot Can you show us your attempt? Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
silent install python.msi
Hello list, I am using the python.msi (at the moment 2.6) in a project and want to deploy the python package smoothly and nearly automatically. So my question is, if the python.msi provides some parameters, to pass the information like which components to install and the install path, without popping up all the dialogs? I do not want to use the default install path! Thanks a lot and kind regards Cornelius signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Py_Initialize() fails on windows when SDL.h is included.
I began porting one of my projects from linux (no problems under
linux) to windows, but I am getting the following problem when
attempting to run it (This was within gdb)
warning: Fatal Python error:
warning: Py_Initialize: can't initialize sys standard streams
warning:
I narrowed it down the following testcase,
#include
#include
int main(int argc, char*argv[])
{
Py_Initialize();
}
commenting out the first include (SDL/SDL.h) allows it to run w/o any problems.
SDL-1.2.13, Python 3.1.3 (Also tested w/ 3.2.), GCC 4.5.1,
w32api-3.17.1, mingw-rt-3.18 (Toolchain is a linux to windows cross
compiler, designed from
http://nathancoulson.com/proj_cross_mingw.shtml)
I noticed when I mess with the include order (Python.h before SDL.h), it gives
3rdparty/i686-pc-mingw32/include/SDL/SDL_config.h:131:0: warning:
"HAVE_SNPRINTF" redefined
3rdparty/i686-pc-mingw32/include/python3.2/pyerrors.h:361:0: note:
this is the location of the previous definition
it is defined in SDL_config.h as
#define HAVE_SNPRINTF 1
although no clue if it's related... probably a red herring
--
Nathan Coulson (conathan)
--
Location: British Columbia, Canada
Timezone: PST (-8)
Webpage: http://www.nathancoulson.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: A Question on URLLIB
You are doing fine so far :-) However, urllib is quite low level module. Do you know mechanize http://wwwsearch.sourceforge.net/mechanize/ ? I have used it in my crawler. If you want to crawl a specific site for known data then Scrapy http://scrapy.org/ could be useful too. David Marek [email protected] http://davidmarek.cz On Tue, Mar 15, 2011 at 7:10 AM, joy99 wrote: > Dear Group, > I am trying to construct a web based crawler with Python and for that > I am using the URLLIB module, and by doing > import urllib and then trying with urllib.urlopen("url). > Am I going fine? > If some one can kindly highlight if I am doing any mistake. > Best Regards, > Subhabrata Banerjee. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
On Mar 15, 9:20 am, Chris Rebert wrote: > On Tue, Mar 15, 2011 at 1:10 AM, yqyq22 wrote: > > Hi all, > > I would like to put an alphanumeric string like this one > > EE472A86441AF2E629DE360 in a list, then iterate inside the entire > > string lenght and change each digit with a random digit. > > Do u have some suggestion? thanks a lot > > Can you show us your attempt? > > Cheers, > Chris Hi, to be honest i'm a newbye so i don't know where to start, i began in this way but i don't know how to proceeed. list = (EE472A86441AF2E629DE360) Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to schedule execution of code?
On 15/03/2011 07:16, Virgil Stokes wrote: Suppose that I have some Python code (vers. 2.6) that has been converted into an *.exe file and can be executed on a Windows (Vista or 7) platform. What can one do to have this *.exe executed at a set of specific times each day? Well, once you've got an .exe, the question isn't really Python-specific any more. (Even without the .exe it's not really Python-specific...) Use the Windows Scheduler. You can schedule a program to run at certain times and on startup. When it fires up, it can check when it was last run (by writing to a file / registry on firing up) and deciding whether or not it needs to run. The alternative is to have it install as a service and then run its own scheduler loop, but that doesn't offer any real advantage: you're just reinventing the Windows Task Scheduler. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: silent install python.msi
On 15/03/2011 08:30, Cornelius Kölbel wrote: I am using the python.msi (at the moment 2.6) in a project and want to deploy the python package smoothly and nearly automatically. So my question is, if the python.msi provides some parameters, to pass the information like which components to install and the install path, without popping up all the dialogs? I do not want to use the default install path! Have a look here: http://www.python.org/download/releases/2.4/msi/ TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: python script to find Installed programs in Uninstall folder in registry
On 15/03/2011 03:42, KishoreRP wrote: I am working on creating a python script to find Installed programs in Uninstall folder in registry, the script works perfectly fine on 32 bit machines but errors out with a wmi error on 64 bit machines. You don't say what the error is (and your snippet doesn't run without some alterations) so would you mind showing just enough code for the error to occur plus a cut-and-paste of the traceback? > Am not able to get hold of a wmi module for python on 64 bit machines. > Is there one at all? The wmi module is pure Python, relying only on Python & the pywin32 extensions. If you have both of those installed as 64-bit you can just drop the wmi.py module into the right place and go from there. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido rethinking removal of cmp from sort method
Paul Rubin, 15.03.2011 09:00: Ian Kelly writes: I would think that you can sort them with key as long as none of the sequences are equal (which would result in an infinite loop using either method). Why not this? Yes you can do something like that, but look how ugly it is compared with using cmp. I would argue that it's a rare use case, though. In most cases, memory doesn't really matter, and the overhead of a decorated sort is acceptable. In some cases, where space matters, an external sort is a better choice or even the only thing that will work, so all that's left are the cases where speed really needs to be traded for space *and* an external sort is not applicable, and those where things can be expressed more easily using cmp than using a key. For the latter, there's support in the standard library, as Steven pointed out. Now, the question that remains is: are the few remaining cases worth being supported directly, thus complicating the internal source code of the Python runtime? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido rethinking removal of cmp from sort method
Stefan Behnel writes: > the question that remains is: are the few remaining cases worth being > supported directly, thus complicating the internal source code of the > Python runtime? The other cases were supported perfectly well already, and the support was removed. That's just ludicrous in my opinion. -- http://mail.python.org/mailman/listinfo/python-list
exe file sends error
Hi,
I needed to create executable of my python application. Everthing was ok , but
my exe file gives an error such as "unable to open database file",
When I try to add an entry to my database. My icon file is in tha same
directory(data) as my database file and there is no problem about that.
Here is my setup.py:
from distutils.core import setup
import py2exe
from glob import glob
data_files = [("Microsoft.VC90.CRT",
glob(r'c:\dev\ms-vc-runtime\*.*')),("data", glob('Veriler\*'))]
options = {
'py2exe': {
'dll_excludes': [
'MSVCP90.dll'
]
}
}
setup(windows=[{"script": "Nokta Ekleme.pyw","icon_resources": [(1,
"Veriler\Alarko.ico")]}], options=options, data_files=data_files)
Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
yqyq22 wrote: > I would like to put an alphanumeric string like this one > EE472A86441AF2E629DE360 in a list, then iterate inside the entire > string lenght and change each digit with a random digit. What does "change each digit with a random digit"? Do you want to swap two random elements of the sequence with each other? The "random" module contains a tool to generate random permutations, all you would have to do is to split the string into a list, call that function and later join the results. Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: silent install python.msi
Hi Tim, thanks a lot. Exactly what I needed. Couldn't find such a page from python 2.6. Kind regards Cornelius Am 15.03.2011 09:55, schrieb Tim Golden: > On 15/03/2011 08:30, Cornelius Kölbel wrote: >> I am using the python.msi (at the moment 2.6) in a project and want to >> deploy the python package smoothly and nearly automatically. >> >> So my question is, if the python.msi provides some parameters, to pass >> the information like which components to install and the install path, >> without popping up all the dialogs? >> I do not want to use the default install path! > > Have a look here: > > http://www.python.org/download/releases/2.4/msi/ > > TJG signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
yqyq22 writes: > On Mar 15, 9:20 am, Chris Rebert wrote: > > Can you show us your attempt? > > Hi, to be honest i'm a newbye so i don't know where to start Work through the entire Python tutorial, in sequence http://docs.python.org/tutorial/>. Not merely read: work through it, reading the explanations, performing the examples, and experimenting with them until satisfied you understand, before moving on to the next. -- \ “I was gratified to be able to answer promptly and I did. I | `\ said I didn't know.” —Mark Twain, _Life on the Mississippi_ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: A Question on URLLIB
On Mar 15, 1:49 pm, David Marek wrote: > You are doing fine so far :-) > > However, urllib is quite low level module. Do you know > mechanizehttp://wwwsearch.sourceforge.net/mechanize/? I have used it in my > crawler. If you want to crawl a specific site for known data then > Scrapyhttp://scrapy.org/could be useful too. > > David Marek > [email protected]://davidmarek.cz > > On Tue, Mar 15, 2011 at 7:10 AM, joy99 wrote: > > Dear Group, > > I am trying to construct a web based crawler with Python and for that > > I am using the URLLIB module, and by doing > > import urllib and then trying with urllib.urlopen("url). > > Am I going fine? > > If some one can kindly highlight if I am doing any mistake. > > Best Regards, > > Subhabrata Banerjee. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Thanks David,I'll surely try to have a check. -- http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
Le 15/03/2011 09:10, yqyq22 a écrit :
Hi all,
I would like to put an alphanumeric string like this one
EE472A86441AF2E629DE360 in a list, then iterate inside the entire
string lenght and change each digit with a random digit.
Do u have some suggestion? thanks a lot
This can be a way to begin :
s="EE472A86441AF2E629DE360"
for a in s:
print a
The following is a very basic trick to build a list containing the
elements of the string
s="EE472A86441AF2E629DE360"
t=[]
for a in s:
t.append(a)
All that you have to change is t.append(a) into something that
tests if a is a number and append something else in that case.
Depending what you want, you can even do
s.replace("1","ONE").replace("2","TWO").replace("3","FIVE")
This is however far from being random ;)
Have good tests
Laurent
--
http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
yqyq22 wrote: > Hi, to be honest i'm a newbye so i don't know where to start, i began > in this way but i don't know how to proceeed. > list = (EE472A86441AF2E629DE360) "list" is a builtin type, so you shouldn't use it as name for other things. The thing on the right-hand side of the assignment is just the identifier EE47... after stripping the brackets, which don't have a meaning there. I'd suggest that you start reading a Python tutorial to get some basics down first. Start reading at http://docs.python.org. Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing many python scripts, in a large corporate environment.
On Tuesday, March 15, 2011 12:44:48 AM UTC-4, bukzor wrote: > When looking at google code search, this kind of code is > rampant (below). Is everyone really happy with this? > > sys.path.insert(0, > os.path.dirname(os.path.dirname( > os.path.dirname(os.path.abspath(__file__) Applications and libraries should be properly packaged (e.g. distutils, egg, rpm, deb, msi, etc). If that can't be done for some reason, then we're stuck with kludges. If you could just get a .pth file symlink'd to site-packages. -- http://mail.python.org/mailman/listinfo/python-list
Exe. error
Hi,
I created an executable version of my application succesfully. It is just a
basic database related app. So it has a database and an icon file in the same
directory called "data".
When I try to add an entry to my database using the .exe file, it gives an
error such as "unable to open database file". But there is no problem with the
icon.
Could anyone help me?
Thanks.
Here is my setup.py:
from distutils.core import setup
import py2exe
from glob import glob
data_files = [("Microsoft.VC90.CRT",
glob(r'c:\dev\ms-vc-runtime\*.*')),("data", glob('Veriler\*'))]
options = {
'py2exe': {
'dll_excludes': [
'MSVCP90.dll'
]
}
}
setup(windows=[{"script": "Nokta Ekleme.pyw","icon_resources": [(1,
"Veriler\Alarko.ico")]}], options=options, data_files=data_files)
--
http://mail.python.org/mailman/listinfo/python-list
Good literature about python twisted
Hi, Just wanted to learn more about python twisted and wanted to buy the O'Reilly book. However I noticed, that the book is from 2005. Is this book still worth it or is there anything better to learn about twisted. I though about buying a paper book in order to be able to read in in the train. If there is however a reall nice online document, then I wouldn't object of not buying a book at all. Thanks in advance for any suggestions -- http://mail.python.org/mailman/listinfo/python-list
Py2exe problem with pyqt+matplotlib
I everyone,
I'm trying to write a setup file for py2exe (0.6.9) to convert my
script into a windows (on win 7) executable. In my script (python2.6)
I use PyQt and matplotlib. Here is the setup.py file:
from distutils.core import setup
import py2exe
import matplotlib as mpl
import glob, shutil
mpl.use('qt4agg')
shutil.rmtree("build", ignore_errors=True)
includes = ['sip', 'PyQt4', 'PyQt4.QtGui', 'matplotlib.backends',
"win32com", "win32service", "win32serviceutil",
"win32event",
"sqlalchemy.dialects.mssql", "pyodbc", "datetime",
"decimal",
"sqlalchemy.dialects.mysql", "MySQLdb"]
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test',
'wx']
packages = ['matplotlib', 'pytz', "encodings"]
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll',
'tcl84.dll',
"libgdk_pixbuf-2.0-0.dll", 'tk84.dll']
data_files = mpl.get_py2exe_datafiles()
setup(name="MyProg",
windows=[{"script": 'Main.pyw',
"icon_resources": [(1, "colorrulex.ico")]}],
options = {"py2exe": {"compressed":2, "optimize":2,
"includes":includes,
"excludes": excludes, "packages":
packages,
"dll_excludes": dll_excludes,
"bundle_files":2,
"dist_dir":'dist', "xref":False,
"skip_archive":False, "ascii": False,
"custom_boot_script":''}},
zipfile = r'lib\library.zip',
data_files=data_files
)
If I run 'python setup.py py2exe' at the command line the executable
is successfully created, but when I run MyProg.exe I get the following
error:
Traceback (most recent call last):
File "Main.pyw", line 4, in
File "zipextimporter.pyo", line 82, in load_module
File "gui\tree\ComponentTree.pyo", line 2, in
File "zipextimporter.pyo", line 82, in load_module
File "gui\stage\Item.pyo", line 6, in
File "zipextimporter.pyo", line 82, in load_module
File "components\CompDataView.pyo", line 10, in
File "zipextimporter.pyo", line 82, in load_module
File "components\dataview\PlotPanel.pyo", line 2, in
File "zipextimporter.pyo", line 82, in load_module
File "plot\PlotCanvas.pyo", line 8, in
File "zipextimporter.pyo", line 82, in load_module
File "pylab.pyo", line 1, in
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\pylab.pyo", line 263, in
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\pyplot.pyo", line 95, in
File "matplotlib\backends\__init__.pyo", line 25, in pylab_setup
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib\backends\backend_tkagg.pyo", line 8, in
ImportError: No module named Tkinter
Obviously Tkinter is not imported since I'm using pyqt, so can anyone
point me out what I'm doing wrong?
Thanks in advance!
--
http://mail.python.org/mailman/listinfo/python-list
Re: alphanumeric list
On Mar 15, 11:02 am, Laurent Claessens wrote:
> Le 15/03/2011 09:10, yqyq22 a crit :
>
> > Hi all,
> > I would like to put an alphanumeric string like this one
> > EE472A86441AF2E629DE360 in a list, then iterate inside the entire
> > string lenght and change each digit with a random digit.
> > Do u have some suggestion? thanks a lot
>
> This can be a way to begin :
>
> s="EE472A86441AF2E629DE360"
> for a in s:
> print a
>
> The following is a very basic trick to build a list containing the
> elements of the string
>
> s="EE472A86441AF2E629DE360"
> t=[]
> for a in s:
> t.append(a)
>
> All that you have to change is t.append(a) into something that
> tests if a is a number and append something else in that case.
>
> Depending what you want, you can even do
>
> s.replace("1","ONE").replace("2","TWO").replace("3","FIVE")
>
> This is however far from being random ;)
>
> Have good tests
> Laurent
Laurent thanks a lot very much!!! really appreciated it.. now i have a
good start point thanks again
--
http://mail.python.org/mailman/listinfo/python-list
Re: Good literature about python twisted
On Tue, 15 Mar 2011 04:34:52 -0700, gelonida wrote: > Hi, > > Just wanted to learn more about python twisted and wanted to buy the > O'Reilly book. > > However I noticed, that the book is from 2005. > > > Is this book still worth it or is there anything better to learn about > twisted. > > I though about buying a paper book in order to be able to read in in the > train. > > If there is however a reall nice online document, then I wouldn't object > of not buying a book at all. > > > Thanks in advance for any suggestions I bought and read that book a couple of years ago, and found that it didn't help me much. I came away with a very shaky understanding of Twisted's principles. I still am very shaky - I'd love to find some Twisted docs that will help the light bulb to go on, as Twisted seems like a very handy tool. -- http://mail.python.org/mailman/listinfo/python-list
Re: Get Path of current Script
On Mar 14, 10:25 am, Alexander Schatten wrote:
> Hi,
>
> could someone help me with a small problem? I wrote a Python script
> that does some RegEx... transformations. Now, this script loads some
> configuration data from a file located in the same directory:
>
> open ('config.txt', 'r').
>
> However, this only works when I execute the script being in the
> directory where the script is locates, because otherwise, of course,
> this config file is not found, as the path is relative. Now my
> question: is there an easy way (API) to get the directory of the
> currently running script? Something along the line of:
>
> open (API.getCurrentPath + 'config.txt', 'r').
>
> thanks a lot,
>
> cheers
>
> Alex
os.path.join(sys.path[0], 'config.txt')
If the script and config.txt are in /tmp this will return '/tmp/
config.txt' no matter from which directory you started the script.
Mario
--
http://mail.python.org/mailman/listinfo/python-list
argparse, tell if arg was defaulted
Is there any way to tell if an arg value was defaulted vs. set on command line? -- http://mail.python.org/mailman/listinfo/python-list
Python script xml-rpc to C# xml-rpc script
If anyone is fluent in python as well as C# using the cook computing
xml-rpc.net library I could really use some help. I have been trying to write
a C# program to access upcdatabase.com without much luck. I have a working
python script. Would anyone be willing to show me the C# equivalent to this
python script might be. Thank you
#!/usr/bin/env python
#
#
import sys
from xmlrpclib import ServerProxy, Error
rpc_key = 'enter rpc_key here'
if __name__=='__main__':
if len(sys.argv) != 2:
print 'Usage: fetchupc.py '
exit
else:
s = ServerProxy('http://www.upcdatabase.com/xmlrpc')
params = { 'rpc_key': rpc_key, 'upc': sys.argv[1] }
print s.lookup(params)
--
http://mail.python.org/mailman/listinfo/python-list
C++ object in PyObject*?
I am wondering, what is the best way to write a Python module as an
interface to a C++ class? I don't want the C++ object representing the
class to be declared as a global, because then if multiple instances
in Python would be created, they would be using the same C++ object
instance, correct?
So it seems to me that there has to be a way to create an object, and
stick it in PyObject *self, since that is passed as an argument to
each function making up the Python module. Then, if multiple
instances of the Python object would be created, they would be
referencing different C++ objects on the back end. Thoughts?
So something like this:
static PyObject* module_function(PyObject *self, PyObject *args) {
MyCrazyCPPObject myobj;
self.add(myobj);
return Py_Something;
}
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python script xml-rpc to C# xml-rpc script
On Tue, 2011-03-15 at 08:00 -0700, Ymtrader wrote: > If anyone is fluent in python as well as C# using the cook computing > xml-rpc.net library I could really use some help. I have been trying > to write a C# program to access upcdatabase.com without much luck. Yes, I've used both. > have a working python script. Would anyone be willing to show me the > C# equivalent to this python script might be. Thank you If you ask on an appropriate forum - yes. [the cook computing forum or the Mono list]. This is *not* a Python question. -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ object in PyObject*?
Richard, 15.03.2011 16:16: I am wondering, what is the best way to write a Python module as an interface to a C++ class? Cython. http://cython.org Here are a couple of tutorials for your use case: http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html http://docs.cython.org/src/tutorial/clibraries.html Stefan -- http://mail.python.org/mailman/listinfo/python-list
calling 64 bit routines from 32 bit matlab on Mac OS X
Howdy, I have run into an issue that I am not sure how to deal with, and would appreciate any insight anyone could offer. I am running on Mac OS X 10.5 and have a reasonably large tool chain including python, PyQt, Numpy... If I do a "which python", I get "Mach-O executable i386". I need to call some commercial 3rd party C extension code that is 64 bit. Am I just out of luck or is there something that I can do? thanks, Danny -- http://mail.python.org/mailman/listinfo/python-list
RE: newbie question (for loop)
In addition, "list" is a reserved word in python and while you can rebind it, it usually not recommended. Unless IPython is different? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -Original Message- From: [email protected] [mailto:[email protected]] On Behalf Of Chris Rebert Sent: Tuesday, March 15, 2011 3:18 AM To: Sachin Kumar Sharma Cc: [email protected] Subject: Re: newbie question (for loop) On Tue, Mar 15, 2011 at 1:01 AM, Sachin Kumar Sharma wrote: > I am getting error on the following syntax while running in Ipython and > spyder and I failed to figure out why > > for i in range(len(list)) > ^ > SyntaxError: invalid syntax You forgot the required colon (":"). It should be for i in range(len(list)): # note trailing colon Cheers, Chris -- "BB"? http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities. -- http://mail.python.org/mailman/listinfo/python-list
Re: argparse, tell if arg was defaulted
- Original message - > Is there any way to tell if an arg value was defaulted vs. set on > command line? > I guess if you need to care about the difference, you shouldn't set a default. -- regards, kushal -- http://mail.python.org/mailman/listinfo/python-list
Re: argparse, tell if arg was defaulted
On 3/15/11 9:54 AM, Neal Becker wrote:
Is there any way to tell if an arg value was defaulted vs. set on command line?
No. If you need to determine that, don't set a default value in the
add_argument() method. Then just check for None and replace it with the default
value and do whatever other processing for the case where the user does not
specify that argument.
parser.add_argument('-f', '--foo', help="the foo argument [default: bar]")
args = parser.parse_args()
if args.foo is None:
args.foo = 'bar'
print 'I'm warning you that you did not specify a --foo argument.'
print 'Using default=bar.'
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list
email library
Hi, Im completely confused from email library. When you parse email from file it creates object Message. f = open(emailFile, 'r') msg = email.message_from_file(f) f.close() How can I access RAW header of email represented by object msg? I dont wanna access each header field by hand. Im doing another parsing, searching for attachments and so on, with email, but i need write raw data of email too. Do I have to allocate another memory for that emailFile? (by mmap or f=open(rawemail). Thanks Best, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido rethinking removal of cmp from sort method
On Tue, Mar 15, 2011 at 2:00 AM, Paul Rubin wrote: > Ian Kelly writes: >> I would think that you can sort them with key as long as none of the >> sequences are equal (which would result in an infinite loop using >> either method). Why not this? > > Yes you can do something like that, but look how ugly it is compared > with using cmp. Actually, how would you do it with cmp? You would need to tee off the iterators in some way so that each comparison gets the same data as the last one, which sounds like a major hassle. Or were you talking about passing in generator functions rather than generator objects and reinitializing them for each comparison? If that's the case then the key version can be a fair amount simpler since you wouldn't need to bother with caching. -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I handle socket receiving?
On Mar 14, 1:33 pm, MRAB wrote: > On 14/03/2011 19:47, Hans wrote: > > > > > On Mar 12, 10:13 pm, Tim Roberts wrote: > >> Hans wrote: > > >>> I'm thinking to write a code which to: > >>> 1. establish tons of udp/tcp connections to a server > > >> What does "tons" mean? Tens? Hundreds? > > >>> my question is how should I handle receiving traffic from each > >>> connection respectively? > > >> You're really going to want to use "select". You can store the objects in > >> a dictionary where the key is the socket number. That way, you can use the > >> result of the select and get your network object directly. > >> -- > >> Tim Roberts, [email protected] > >> Providenza& Boekelheide, Inc. > > > I wrote code like this: > > main proc: > > import socket_thread > > #start 1000 connection > > while i<1000: > > my_socket=socket_thread.socket_thread(i,host,port) > > my_socket.send(some_data) > > my_socket.recv() > > This won't run as-is because you never assign to "i". > > > > > > > socket_thread.py > > class socket_thread: > > def __init__: > > self.soc_handle=socket.socket(socket.IF_INET,socket.DGRAM) > > def send(data): > > self.soc_handle.send(data) > > def recv(): > > while 1: > > > input_list,output_list,exec_list=select.select([self.soc_handle],[],[], > > 2) > > data=input_list[0].recv(2048) > > print data > > > But it does not work as I hope. main proc can only initiate one thread > > and then trapped by it, cannot get out. > > I'm sure I missed something but I don't know. Thanks for any help. > > Your "socket_thread" class is just a normal class. You create an > instance, use it to send data, and then call its "recv" method, which > loops forever.- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Thanks. "i" problem is OK, I can find and fix it easily. I also understand the second problem, but I don't know how to fix it. What's your meaning of "normal class"? Can I specify it as some special class and then it can work as I hope? thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: argparse, tell if arg was defaulted
Robert Kern wrote:
> On 3/15/11 9:54 AM, Neal Becker wrote:
>> Is there any way to tell if an arg value was defaulted vs. set on command
>> line?
>
> No. If you need to determine that, don't set a default value in the
> add_argument() method. Then just check for None and replace it with the
> default value and do whatever other processing for the case where the user
> does not specify that argument.
>
> parser.add_argument('-f', '--foo', help="the foo argument [default: bar]")
>
> args = parser.parse_args()
> if args.foo is None:
> args.foo = 'bar'
> print 'I'm warning you that you did not specify a --foo argument.'
> print 'Using default=bar.'
>
Not a completely silly use case, actually. What I need here is a combined
command line / config file parser.
Here is my current idea:
-
parser = OptionParser()
parser.add_option ('--opt1', default=default1)
(opt,args) = parser.parse_args()
import json, sys
for arg in args:
print 'arg:', arg
d = json.load(open (arg, 'r'))
parser.set_defaults (**d)
(opt,args) = parser.parse_args()
---
parse_args() is called 2 times. First time is just to find the non-option
args,
which are assumed to be the name(s) of config file(s) to read. This is used to
set_defaults. Then run parse_args() again.
--
http://mail.python.org/mailman/listinfo/python-list
Re: argparse, tell if arg was defaulted
Neal Becker wrote:
Robert Kern wrote:
On 3/15/11 9:54 AM, Neal Becker wrote:
Is there any way to tell if an arg value was defaulted vs. set on command
line?
No. If you need to determine that, don't set a default value in the
add_argument() method. Then just check for None and replace it with the
default value and do whatever other processing for the case where the user
does not specify that argument.
parser.add_argument('-f', '--foo', help="the foo argument [default: bar]")
args = parser.parse_args()
if args.foo is None:
args.foo = 'bar'
print 'I'm warning you that you did not specify a --foo argument.'
print 'Using default=bar.'
Not a completely silly use case, actually. What I need here is a combined
command line / config file parser.
Here is my current idea:
-
parser = OptionParser()
parser.add_option ('--opt1', default=default1)
(opt,args) = parser.parse_args()
import json, sys
for arg in args:
print 'arg:', arg
d = json.load(open (arg, 'r'))
parser.set_defaults (**d)
(opt,args) = parser.parse_args()
---
parse_args() is called 2 times. First time is just to find the non-option args,
which are assumed to be the name(s) of config file(s) to read. This is used to
set_defaults. Then run parse_args() again.
Is that what you want ?
"user CLI > json defaults > script default"
If so, your idea seems good.
Otherwise
"--opt1" in sys.argv
would tell you if an option has been specified through the CLI. But it
seems to me anti-pattern. You should not need to parse the CLI, that's
the purpose of using optparse.
JM
--
http://mail.python.org/mailman/listinfo/python-list
Re: newbie question (for loop)
You have to add the colon to the end of the statement if this is an accurate representation of the statement so: "for i in range(len(list)):" instead of "for i in range(len(list))" On 3/15/2011 2:01 AM, Sachin Kumar Sharma wrote: BB, I am getting error on the following syntax while running in Ipython and spyder and I failed to figure out why for i in range(len(list)) Error for i in range(len(list)) ^ SyntaxError: invalid syntax where list is a list defined as a collection of words and it is OK prints fine. Kindly advise. Cheers Sachin * Sachin Kumar Sharma* Senior Geomodeler __ -- ___ Timothy W. Morneau /National Semiconductor/ Phone: (303) 845-4108 Fax:(303) 845-4005 email: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Py2exe problem with pyqt+matplotlib
On 2:59 PM, Massi wrote: > I everyone, > > I'm trying to write a setup file for py2exe (0.6.9) to convert my > script into a windows (on win 7) executable. In my script (python2.6) > I use PyQt and matplotlib. Here is the setup.py file: > ImportError: No module named Tkinter > > Obviously Tkinter is not imported since I'm using pyqt, so can anyone > point me out what I'm doing wrong? > Thanks in advance! PyQt doesn't use Tkinter, but matplotlib does! -John -- http://mail.python.org/mailman/listinfo/python-list
Re: argparse, tell if arg was defaulted
On 3/15/11 12:46 PM, Neal Becker wrote:
Robert Kern wrote:
On 3/15/11 9:54 AM, Neal Becker wrote:
Is there any way to tell if an arg value was defaulted vs. set on command
line?
No. If you need to determine that, don't set a default value in the
add_argument() method. Then just check for None and replace it with the
default value and do whatever other processing for the case where the user
does not specify that argument.
parser.add_argument('-f', '--foo', help="the foo argument [default: bar]")
args = parser.parse_args()
if args.foo is None:
args.foo = 'bar'
print 'I'm warning you that you did not specify a --foo argument.'
print 'Using default=bar.'
Not a completely silly use case, actually. What I need here is a combined
command line / config file parser.
Here is my current idea:
-
parser = OptionParser()
parser.add_option ('--opt1', default=default1)
(opt,args) = parser.parse_args()
import json, sys
for arg in args:
print 'arg:', arg
d = json.load(open (arg, 'r'))
parser.set_defaults (**d)
(opt,args) = parser.parse_args()
---
parse_args() is called 2 times. First time is just to find the non-option args,
which are assumed to be the name(s) of config file(s) to read. This is used to
set_defaults. Then run parse_args() again.
I think that would work fine for most cases. Just be careful with the argument
types that may consume resources. E.g. type=argparse.FileType().
You could also make a secondary parser that just extracts the config-file
argument:
[~]
|25> import argparse
[~]
|26> config_parser = argparse.ArgumentParser(add_help=False)
[~]
|27> config_parser.add_argument('-c', '--config', action='append')
_AppendAction(option_strings=['-c', '--config'], dest='config', nargs=None,
const=None, default=None, type=None, choices=None, help=None, metavar=None)
[~]
|28> parser = argparse.ArgumentParser()
[~]
|29> parser.add_argument('-c', '--config', action='append') # For the --help
string.
_AppendAction(option_strings=['-c', '--config'], dest='config', nargs=None,
const=None, default=None, type=None, choices=None, help=None, metavar=None)
[~]
|30> parser.add_argument('-o', '--output')
_StoreAction(option_strings=['-o', '--output'], dest='output', nargs=None,
const=None, default=None, type=None, choices=None, help=None, metavar=None)
[~]
|31> parser.add_argument('other', nargs='*')
_StoreAction(option_strings=[], dest='other', nargs='*', const=None,
default=None, type=None, choices=None, help=None, metavar=None)
[~]
|32> argv = ['-c', 'config-file.json', '-o', 'output.txt', 'other', 'arguments']
[~]
|33> known, unknown = config_parser.parse_known_args(argv)
[~]
|34> known
Namespace(config=['config-file.json'])
[~]
|35> unknown
['-o', 'output.txt', 'other', 'arguments']
[~]
|36> for cf in known.config:
...> # Load d from file.
...> parser.set_defaults(**d)
...>
[~]
|37> parser.parse_args(unknown)
Namespace(config=None, other=['other', 'arguments'], output='output.txt')
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list
Using vectors in single NLP constraint inside proc iml with call statement
I have two variables that are stored in a data set and also are stored as matrices and vectors. I want to formulate only one constraint that is a function of all the data set's observations (or elements of these vectors) and a decision variable. Suppose the two stored variables (two vectors) are a and b, and x is a decision variable. My constraint is: sum over i for [ (ai)^2 * bi/ (ai+x)] = 1, can you help me to include this constraint inside proc iml in order to use call nlpqn ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Good literature about python twisted
On Mar 15, 2:18 pm, Daniel Mahoney wrote: > On Tue, 15 Mar 2011 04:34:52 -0700, gelonida wrote: > > Hi, > > > Just wanted to learn more about python twisted and wanted to buy the > > O'Reilly book. > > > However I noticed, that the book is from 2005. > > > Is this book still worth it or is there anything better to learn about > > twisted. > > > I though about buying a paper book in order to be able to read in in the > > train. > > > If there is however a reall nice online document, then I wouldn't object > > of not buying a book at all. > > > Thanks in advance for any suggestions > > I bought and read that book a couple of years ago, and found that it > didn't help me much. I came away with a very shaky understanding of > Twisted's principles. I still am very shaky - I'd love to find some > Twisted docs that will help the light bulb to go on, as Twisted seems > like a very handy tool. Thanks a lot for your answer. o it seems another book or some other documentation would be great. Does anyone have recommendations? -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing many python scripts, in a large corporate environment.
> Is everyone really happy with this? I'm not happy with this. In fact, if Python 3.3 came out with a solution for this problem, it would be a major motivation for me to migrate. I don't think that it would take much to fix either. Perhaps if Python looked in the current directory for ".pth" files? Instead of having some boiler-plate at the top of every file, you could specify your paths there. I haven't thought about it enough to know that this idea specifically is the best way to go, but it would be nice if there were some way of solving this cleanly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Good literature about python twisted
Hi, The krondo blog is a good place to start : http://krondo.com/?page_id=1327 It's a serie of 22 blogposts, introducing asynchronous programming and twisted. Cheers, Nelle On 15 March 2011 19:18, gelonida wrote: > On Mar 15, 2:18 pm, Daniel Mahoney wrote: > > On Tue, 15 Mar 2011 04:34:52 -0700, gelonida wrote: > > > Hi, > > > > > Just wanted to learn more about python twisted and wanted to buy the > > > O'Reilly book. > > > > > However I noticed, that the book is from 2005. > > > > > Is this book still worth it or is there anything better to learn about > > > twisted. > > > > > I though about buying a paper book in order to be able to read in in > the > > > train. > > > > > If there is however a reall nice online document, then I wouldn't > object > > > of not buying a book at all. > > > > > Thanks in advance for any suggestions > > > > I bought and read that book a couple of years ago, and found that it > > didn't help me much. I came away with a very shaky understanding of > > Twisted's principles. I still am very shaky - I'd love to find some > > Twisted docs that will help the light bulb to go on, as Twisted seems > > like a very handy tool. > > > > Thanks a lot for your answer. > > o it seems another book or some other documentation would be great. > > Does anyone have recommendations? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to schedule execution of code?
On 15-03-11 08:16, Virgil Stokes wrote: Suppose that I have some Python code (vers. 2.6) that has been converted into an *.exe file and can be executed on a Windows (Vista or 7) platform. What can one do to have this *.exe executed at a set of specific times each day? In addition, if a day is missed (e.g. computer on which it resides goes down), then it will be executed the next time the computer is successfully started up. It might be useful to know that the purpose of this code is to collect data from a set of RSS feeds. Any suggestions would be appreciated. Have you tried the Windows Task Scheduler tool? Irmen -- http://mail.python.org/mailman/listinfo/python-list
using simplejson.dumps to encode a dictionary to json
Hi there,
I am attempting to use simplejson.dumps to convert a dictionary to a json
encoded string.
For some reason this doesn't work - it would be awesome if someone could give
me a clue as to why.
loginreq = {"username":username, "password":password, "productType":"CFD_Demo"}
authreq_data = {"req":loginreq}
authreq_data = simplejson.dumps(authreq_data)
A
#The dictionary contains a dictionary
--
http://mail.python.org/mailman/listinfo/python-list
Re: calling 64 bit routines from 32 bit matlab on Mac OS X
On Mar 15, 2011, at 11:58 AM, Danny Shevitz wrote: > Howdy, > > I have run into an issue that I am not sure how to deal with, and would > appreciate any insight anyone could offer. > > I am running on Mac OS X 10.5 and have a reasonably large tool chain including > python, PyQt, Numpy... If I do a "which python", I get "Mach-O executable > i386". > > I need to call some commercial 3rd party C extension code that is 64 bit. Am I > just out of luck or is there something that I can do? Depends on how desperate you are. You could install 64-bit Python alongside the 32-bit version, call with the 64-bit C DLL from 64-bit Python using ctypes, and then communicate between the 32- and 64-bit Pythons via pickled objects sent over an interprocess pipe. That solution has a Rube Goldberg-esque charm but not much else to recommend it. I hope you can find something better. Cheers Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: using simplejson.dumps to encode a dictionary to json
If I print authreq_data to screen I get
{"req": {"username": "##", "password": "#", "productType": "CFD_Demo"}}
Essentially I want the inner brackets to be [ ] instead of {} but alternating
on each level so it would be:
{"req": [{"username": "##", "password": "#", "productType":
"CFD_Demo"}]}
as per usual json.
A
--
http://mail.python.org/mailman/listinfo/python-list
Re: using simplejson.dumps to encode a dictionary to json
I'm attempting to write an xml as a json object. the xml object is authreq_data = """ %s CFD_Demo %s """ %(username, password) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk MouseWheel Support
On Mar 10, 1:37 pm, Corey Richardson wrote:
> On 03/10/2011 03:35 PM, Corey Richardson wrote:
>
> > Middle button is Button-3 IIRC, and I think it'd be MouseUp and
> > MouseDown. I'm really not sure though.
>
> It's Button-2 rather.
>
> --
> Corey Richardson
Middle button is button-3 on Mac OS X, and button-2 on Linux and
Windows. Very annoying, to say the least.
For X11, here's a better way to inject MouseWheel events so all
widgets that understand MouseWheel events will work without additional
code:
def mousewheel(e, delta):
try:
w = e.widget.focus_displayof()
except AttributeError:
# e.widget might be string
# if not created by Tkinter (eg., menu tearoff)
return
if w: w.event_generate('', delta=delta,
state=e.state, rootx=e.x_root, rooty=e.y_root,
x=e.x, y=e.y, time=e.time)
root.bind_all('', lambda e, mw=mousewheel: mw(e, 120))
root.bind_all('', lambda e, mw=mousewheel: mw(e, -120))
--
http://mail.python.org/mailman/listinfo/python-list
Re: using simplejson.dumps to encode a dictionary to json
On 15/03/2011 19:40, Aaron wrote:
Hi there,
I am attempting to use simplejson.dumps to convert a dictionary to a json
encoded string.
For some reason this doesn't work - it would be awesome if someone could give
me a clue as to why.
loginreq = {"username":username, "password":password, "productType":"CFD_Demo"}
authreq_data = {"req":loginreq}
authreq_data = simplejson.dumps(authreq_data)
A
#The dictionary contains a dictionary
Which version of Python? Versions of Python since 2.6 come with a
"json" module.
--
http://mail.python.org/mailman/listinfo/python-list
Re: using simplejson.dumps to encode a dictionary to json
On Tue, Mar 15, 2011 at 12:56 PM, Aaron wrote:
> If I print authreq_data to screen I get
>
> {"req": {"username": "##", "password": "#", "productType":
> "CFD_Demo"}}
>
> Essentially I want the inner brackets to be [ ] instead of {} but
> alternating on each level so it would be:
>
> {"req": [{"username": "##", "password": "#", "productType":
> "CFD_Demo"}]}
>
> as per usual json.
I don't think there's a "usual JSON", but anyway, if you want a list,
then just use one:
from json import dumps
loginreq = {"username":username, "password":password, "productType":"CFD_Demo"}
authreq_data = {"req":[loginreq]} # note brackets
authreq_data = dumps(authreq_data)
>>> print(authreq_data)
{"req": [{"username": "USER", "password": "PASS", "productType": "CFD_Demo"}]}
Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: using simplejson.dumps to encode a dictionary to json
On 15/03/2011 19:56, Aaron wrote:
If I print authreq_data to screen I get
{"req": {"username": "##", "password": "#", "productType": "CFD_Demo"}}
Essentially I want the inner brackets to be [ ] instead of {} but alternating
on each level so it would be:
{"req": [{"username": "##", "password": "#", "productType":
"CFD_Demo"}]}
as per usual json.
{... } designates a dict and [...] designates a list.
If you give json the correct structure then it will give you want you
want.
This is a dict:
{"req": [{"username": "##", "password": "#", "productType":
"CFD_Demo"}]}
The value for the key "req" is a list:
[{"username": "##", "password": "#", "productType":
"CFD_Demo"}]
which contains a dict:
{"username": "##", "password": "#", "productType": "CFD_Demo"}
--
http://mail.python.org/mailman/listinfo/python-list
possible to run a python script without installing python?
it seems that if I copy the python.exe binary and the folders associated with it to a server without python, i can run python. does anyone know which files are important to copy and which can be omitted? i know about py2exe and have had no luck with it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Get Path of current Script
On Tuesday, March 15, 2011 9:47:17 AM UTC-4, Mario Rol wrote: > > os.path.join(sys.path[0], 'config.txt') > > If the script and config.txt are in /tmp this will return '/tmp/ > config.txt' no matter from which directory you started the script. You have to be careful about symlinks. Even Windows has support for symlinks, since version 6, via mklink (jaraco.windows can monkeypatch os.readlink to support NTFS symlinks). Maybe it would be better to use setuptools, which will also work for eggs and zip files that don't use __file__: http://packages.python.org/distribute/setuptools.html Included data files are accessible via 'pkg_resources', and the installer can deploy 'console_scripts' and 'gui_scripts' as 'entry_points' in locations specific to each supported platform. -- http://mail.python.org/mailman/listinfo/python-list
Re: Good literature about python twisted
On 03/15/2011 03:18 PM, gelonida wrote: > o it seems another book or some other documentation would be great. > > Does anyone have recommendations? > http://krondo.com/?page_id=1327 -- Corey Richardson -- http://mail.python.org/mailman/listinfo/python-list
Re: using simplejson.dumps to encode a dictionary to json
Rock on, thanks guys. I'm on python 2.5 btw - I use it with google app engine so cannot upgrade unfortunately. A -- http://mail.python.org/mailman/listinfo/python-list
Re: argparse, tell if arg was defaulted
Robert Kern wrote:
> On 3/15/11 12:46 PM, Neal Becker wrote:
>> Robert Kern wrote:
>>
>>> On 3/15/11 9:54 AM, Neal Becker wrote:
Is there any way to tell if an arg value was defaulted vs. set on command
line?
>>>
>>> No. If you need to determine that, don't set a default value in the
>>> add_argument() method. Then just check for None and replace it with the
>>> default value and do whatever other processing for the case where the user
>>> does not specify that argument.
>>>
>>> parser.add_argument('-f', '--foo', help="the foo argument [default: bar]")
>>>
>>> args = parser.parse_args()
>>> if args.foo is None:
>>> args.foo = 'bar'
>>> print 'I'm warning you that you did not specify a --foo argument.'
>>> print 'Using default=bar.'
>>>
>>
>> Not a completely silly use case, actually. What I need here is a combined
>> command line / config file parser.
>>
>> Here is my current idea:
>> -
>>
>> parser = OptionParser()
>> parser.add_option ('--opt1', default=default1)
>>
>> (opt,args) = parser.parse_args()
>>
>> import json, sys
>>
>> for arg in args:
>> print 'arg:', arg
>> d = json.load(open (arg, 'r'))
>> parser.set_defaults (**d)
>>
>> (opt,args) = parser.parse_args()
>> ---
>>
>> parse_args() is called 2 times. First time is just to find the non-option
>> args,
>> which are assumed to be the name(s) of config file(s) to read. This is used
>> to
>> set_defaults. Then run parse_args() again.
>
> I think that would work fine for most cases. Just be careful with the argument
> types that may consume resources. E.g. type=argparse.FileType().
>
> You could also make a secondary parser that just extracts the config-file
> argument:
>
> [~]
> |25> import argparse
>
> [~]
> |26> config_parser = argparse.ArgumentParser(add_help=False)
>
> [~]
> |27> config_parser.add_argument('-c', '--config', action='append')
> _AppendAction(option_strings=['-c', '--config'], dest='config', nargs=None,
> const=None, default=None, type=None, choices=None, help=None, metavar=None)
>
> [~]
> |28> parser = argparse.ArgumentParser()
>
> [~]
> |29> parser.add_argument('-c', '--config', action='append') # For the --help
> string.
> _AppendAction(option_strings=['-c', '--config'], dest='config', nargs=None,
> const=None, default=None, type=None, choices=None, help=None, metavar=None)
>
> [~]
> |30> parser.add_argument('-o', '--output')
> _StoreAction(option_strings=['-o', '--output'], dest='output', nargs=None,
> const=None, default=None, type=None, choices=None, help=None, metavar=None)
>
> [~]
> |31> parser.add_argument('other', nargs='*')
> _StoreAction(option_strings=[], dest='other', nargs='*', const=None,
> default=None, type=None, choices=None, help=None, metavar=None)
>
> [~]
> |32> argv = ['-c', 'config-file.json', '-o', 'output.txt', 'other',
> |'arguments']
>
> [~]
> |33> known, unknown = config_parser.parse_known_args(argv)
>
> [~]
> |34> known
> Namespace(config=['config-file.json'])
>
> [~]
> |35> unknown
> ['-o', 'output.txt', 'other', 'arguments']
>
> [~]
> |36> for cf in known.config:
> ...> # Load d from file.
> ...> parser.set_defaults(**d)
> ...>
>
> [~]
> |37> parser.parse_args(unknown)
> Namespace(config=None, other=['other', 'arguments'], output='output.txt')
>
>
nice!
--
http://mail.python.org/mailman/listinfo/python-list
Re: logging and PyQt4
On Mar 14, 7:40 am, Adrian Casey wrote: > I have a multi-threaded PyQt4 application which has both a GUI and command- > line interface. I am using Qt4's threading because from what I have read, > it is more efficient than the native python threading module. Also, given > most users will probably use the GUI, it seemed to make sense. > > I want a flexible, threadsafeloggingfacility for my application so I was > thinking of using python'sloggingmodule. I need a logger that can log to > the GUI or a terminal depending on how the application is invoked. > > So, my question is -: > > Is it wise to use python'sloggingmodule in conjunction with Qt4 threads? > If not, what are my options apart from writing my ownloggingmodule? > > If it is OK, then I would like to know how to subclass theloggingclass so > that instead of sending output to stdout (as in StreamHandler), it emits Qt4 > signals instead. > > Any help would be appreciated. > > Thank you. > Adrian Casey. Logging certainly works well with PyQt4 in multi-threaded applications, though of course it's based on Python's threading API rather than Qt's. To direct logging output to a GUI, it would be appropriate to develop a Qt/PyQt-aware handler class (derived from logging.Handler) to do the Qt interfacing. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question (for loop)
On Wednesday 16 March 2011 05:48:14 Tim Morneau wrote: > You have to add the colon to the end of the statement if this > is an accurate representation of the statement so: > > "for i in range(len(list)):" instead of "for i in > range(len(list))" > It seems to me that it would be simpler to simply do it like this: mylist = list for var in mylist: (var is an entry in the list - do with it whatever you want to do) The new name mylist should be used in the place where you defined **your** list. (mylist = list is used as an indication only; never use reserved name for a variable name - bad practice that will lead to grief sooner or later). OldAl. -- Algis http://akabaila.pcug.org.au/StructuralAnalysis.pdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Py_Initialize() fails on windows when SDL.h is included.
Recompiling SDL, using --disable-stdio-redirect fixed this problem.
On Tue, Mar 15, 2011 at 1:48 AM, Nathan Coulson wrote:
> I began porting one of my projects from linux (no problems under
> linux) to windows, but I am getting the following problem when
> attempting to run it (This was within gdb)
>
> warning: Fatal Python error:
> warning: Py_Initialize: can't initialize sys standard streams
> warning:
>
>
> I narrowed it down the following testcase,
>
> #include
> #include
>
> int main(int argc, char*argv[])
> {
> Py_Initialize();
> }
>
> commenting out the first include (SDL/SDL.h) allows it to run w/o any
> problems.
>
> SDL-1.2.13, Python 3.1.3 (Also tested w/ 3.2.), GCC 4.5.1,
> w32api-3.17.1, mingw-rt-3.18 (Toolchain is a linux to windows cross
> compiler, designed from
> http://nathancoulson.com/proj_cross_mingw.shtml)
>
> I noticed when I mess with the include order (Python.h before SDL.h), it gives
>
> 3rdparty/i686-pc-mingw32/include/SDL/SDL_config.h:131:0: warning:
> "HAVE_SNPRINTF" redefined
> 3rdparty/i686-pc-mingw32/include/python3.2/pyerrors.h:361:0: note:
> this is the location of the previous definition
>
> it is defined in SDL_config.h as
> #define HAVE_SNPRINTF 1
>
> although no clue if it's related... probably a red herring
>
> --
> Nathan Coulson (conathan)
> --
> Location: British Columbia, Canada
> Timezone: PST (-8)
> Webpage: http://www.nathancoulson.com
>
--
Nathan Coulson (conathan)
--
Location: British Columbia, Canada
Timezone: PST (-8)
Webpage: http://www.nathancoulson.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: possible to run a python script without installing python?
On Mar 15, 4:58 pm, davidj411 wrote: > it seems that if I copy the python.exe binary and the folders > associated with it to a server without python, i can run python. > does anyone know which files are important to copy and which can be > omitted? > > i know about py2exe and have had no luck with it. Wouldn't figuring out how to use py2exe be, well, *easier* than figuring out what a minimal install would look like? Your question can't be answered in the abstract. Something is important if you use it. Without seeing your code (and without detailed knowledge of Python internals), there is no way to tell what that might be. You can of course omit things that you don't use - but because of various dependencies you might be using a file without knowing it. One of the purposes of a tool like py2exe is to automatically handle such dependencies. -- http://mail.python.org/mailman/listinfo/python-list
Re: possible to run a python script without installing python?
On 3/15/2011 4:58 PM, davidj411 wrote: it seems that if I copy the python.exe binary and the folders associated with it to a server without python, i can run python. does anyone know which files are important to copy and which can be omitted? For the 3.2 Windows installation, you should be able to omit Doc, Lib/test, Lib/turtledemo, and Tools. Three of those are optional installs anyway. Lib/idlelib could almost certainly go if not running IDLE from the server (which would be unlikely). If not using tcl/tk, several files in DLLs, Lib, and libs and the tcl directory can go. Translate as needed for *nix. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: possible to run a python script without installing python?
On Tue, Mar 15, 2011 at 8:58 PM, davidj411 wrote: > it seems that if I copy the python.exe binary and the folders > associated with it to a server without python, i can run python. > does anyone know which files are important to copy and which can be > omitted? > > i know about py2exe and have had no luck with it. What's the reason for wanting to avoid installing Python? - are you just trying to save disk space? If it's a case of not having admin rights, you can just copy the Python directory, I don't believe it has any dependencies anywhere else. Katie -- CoderStack http://www.coderstack.co.uk The Software Developer Job Board -- http://mail.python.org/mailman/listinfo/python-list
Multiprocessing.Process Daemonic Behavior
Greetings, I'm trying to understand the behavior of the multiprocessing.Process daemonic attribute. Based on what I have read, if a Process ( X ) is created, and before it is started ( X.start() ), I should be able to set the process as daemonic using X.daemon=True. Once this attribute is set, if the parent process terminates, all daemonic process should also terminate. To experiment with this, I have written the following script. #-- BEGIN SCRIPT --# #!/usr/bin/env python from time import sleep from os import getpid from multiprocessing import Process class worker(Process): def __init__(self, id): Process.__init__(self) self.id = id def run(self): try: print 'Starting thread %s (pid:%s)' % (self.id, getpid()) while True: print 'Hello from thread %s (pid:%s)' % (self.id, getpid()) sleep(1) except KeyboardInterrupt: print '** KeyboardInterrupt captured. Shutting down thread %d (pid:%s) ' % (self.id, getpid()) if __name__ == '__main__': print 'Starting main (pid:%s)' % ( getpid()) t = [] try: for i in range(2): w = worker(i) w.daemon=True if w._daemonic: print 'thread %d is daemonic' % i t.append(w) try: for i in range(len(t)): t[i].start() loop = True while loop: loop = False for i in range(len(t)): if t[i].is_alive(): loop = True if not t[i]._daemonic: print 'thread %d is NOT daemonic' % i sleep(1) except KeyboardInterrupt: raise except KeyboardInterrupt: print 'KeyboardInterrupt captured. Shutting down main (pid:%s)' % getpid() print 'Shutting down' sleep(10) print 'Done.' # -- END SCRIPT -- # From the command line, if I run the script and then enter ctrl-C the program and daemonic children terminate as I would expect. ~/temp$ ./threadtest.py Starting main (pid:13395) thread 0 is daemonic thread 1 is daemonic Starting thread 0 (pid:13396) Hello from thread 0 (pid:13396) Starting thread 1 (pid:13397) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) ^C KeyboardInterrupt captured. Shutting down main (pid:13395) Shutting down ** KeyboardInterrupt captured. Shutting down thread 0 (pid:13396) ** KeyboardInterrupt captured. Shutting down thread 1 (pid:13397) Done. Likewise, if i use a 'kill -2 13395', the results are the same (13395 being the parent pid). If I use a 'kill -2 13396 13397', the daemonic children terminate, and the main closes as one would expect (13396 and 13397 being the children pids). However, if I use a 'kill 13395' (or something other then a SIGINT) the parent process terminates and the daemonic children CONTINUE TO PROCESS. The children essentially become zombies merrily meandering around the system. Really, is there anything worse then a daemonic zombie? I would have expected the daemonic children processes to terminate with the parent process, regardless of how the parent process terminates, either normally or forcefully. I would love to be enlightened Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Process Daemonic Behavior
On 16/03/2011 02:34, John L. Stephens wrote: Greetings, I'm trying to understand the behavior of the multiprocessing.Process daemonic attribute. Based on what I have read, if a Process ( X ) is created, and before it is started ( X.start() ), I should be able to set the process as daemonic using X.daemon=True. Once this attribute is set, if the parent process terminates, all daemonic process should also terminate. To experiment with this, I have written the following script. #-- BEGIN SCRIPT --# #!/usr/bin/env python from time import sleep from os import getpid from multiprocessing import Process class worker(Process): def __init__(self, id): Process.__init__(self) self.id = id def run(self): try: print 'Starting thread %s (pid:%s)' % (self.id, getpid()) while True: print 'Hello from thread %s (pid:%s)' % (self.id, getpid()) sleep(1) except KeyboardInterrupt: print '** KeyboardInterrupt captured. Shutting down thread %d (pid:%s) ' % (self.id, getpid()) if __name__ == '__main__': print 'Starting main (pid:%s)' % ( getpid()) t = [] try: for i in range(2): w = worker(i) w.daemon=True if w._daemonic: print 'thread %d is daemonic' % i t.append(w) try: for i in range(len(t)): t[i].start() loop = True while loop: loop = False for i in range(len(t)): if t[i].is_alive(): loop = True if not t[i]._daemonic: print 'thread %d is NOT daemonic' % i sleep(1) except KeyboardInterrupt: raise except KeyboardInterrupt: print 'KeyboardInterrupt captured. Shutting down main (pid:%s)' % getpid() print 'Shutting down' sleep(10) print 'Done.' # -- END SCRIPT -- # From the command line, if I run the script and then enter ctrl-C the program and daemonic children terminate as I would expect. ~/temp$ ./threadtest.py Starting main (pid:13395) thread 0 is daemonic thread 1 is daemonic Starting thread 0 (pid:13396) Hello from thread 0 (pid:13396) Starting thread 1 (pid:13397) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) Hello from thread 0 (pid:13396) Hello from thread 1 (pid:13397) ^C KeyboardInterrupt captured. Shutting down main (pid:13395) Shutting down ** KeyboardInterrupt captured. Shutting down thread 0 (pid:13396) ** KeyboardInterrupt captured. Shutting down thread 1 (pid:13397) Done. Likewise, if i use a 'kill -2 13395', the results are the same (13395 being the parent pid). If I use a 'kill -2 13396 13397', the daemonic children terminate, and the main closes as one would expect (13396 and 13397 being the children pids). However, if I use a 'kill 13395' (or something other then a SIGINT) the parent process terminates and the daemonic children CONTINUE TO PROCESS. The children essentially become zombies merrily meandering around the system. Really, is there anything worse then a daemonic zombie? I would have expected the daemonic children processes to terminate with the parent process, regardless of how the parent process terminates, either normally or forcefully. I would love to be enlightened At a guess I'd say that when the parent process terminates normally (of its own accord) or is told to quit (SIGINT) it terminates its daemonic children, but it's just killed (SIGKILL or uncaught signal) then it's just stopped dead. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Process Daemonic Behavior
On Wed, Mar 16, 2011 at 12:34 PM, John L. Stephens wrote: > I would have expected the daemonic children processes to terminate with the > parent process, regardless of how the parent process terminates, either > normally or forcefully. As I understand it. If you forcibly kill the parent process with the KILL signal then any child procesases that were created become zombies. You also can't handle the KILL signal in your application (nor can the multiprocessing library) and so it therefore cannot cleanup and terminate any child processes in the normal way. cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list
To collect a basic body hair incidents can be avoided, if the consultant is still an abs
www.airmax-seller.com To collect a basic body hair incidents can be avoided, if the consultant is still an abstraction. Stoudemire capacity and liquidity, cheap air Jordan heel once again as women’s basketball player is very good, good players introduced inspiration branch. She and her fertility decline, the impact and tilt shoes Jordan sports shoes, Nike Designer Tracy Teague to see other Nike Air Max . Fei Qiao single men’s basketball shoes Air Jordan mitigation, the latest technology with the outside air, it must be somewhat similar to the best player over the exact shoe in honor of their visit to Jordan confirmed. Are you satisfied, said: “Cotton wool shawl or glass, absolutely must be at night, or relax cotton or silk cushion the pain of that instrument should be effective integration of feeling .. the right of Jordan will be your perception of the cost of Jordan? Filled Flowering Advisory painful skin high heels. Nike Air Max is perhaps the most famous players, we always want to see is the back side. Similarly, Air Max 95 we see a different match gray shoes, the shadow of the side position. Pressure will be dark gray and white, can also be found in the main at the same time. Air Max 90 Premium white, ice blue outersole can also be honest and look at the bottom of the shoes better. Nike Air Max 95 has been Eastbay, Nike, is considered to play an account soon. LeBron may have burned some bridges this summer, but that did not stop Nike to create a series of color combinations of secondary signature, the Air Max 95 . This couple just landed on the finish and sports a color treatment Akron-esque. Marina fell leather is used for the fenders and match the language of mesh belt midsole and midfoot Flywire. Gold is used as the main accent color, which appears in all key accent pairs, including the Lion logo near the heel roof replaced LBJ23 seen in other color combinations. Grab a pair for $ 110. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any python library that parse c++ source code statically
Thank you guys. Seems it's rather complex. -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing many python scripts, in a large corporate environment.
On Mar 15, 12:24 pm, booklover wrote: > > Is everyone really happy with this? > > I'm not happy with this. In fact, if Python 3.3 came out with a > solution for this problem, it would be a major motivation for me to > migrate. > > I don't think that it would take much to fix either. Perhaps if Python > looked in the current directory for ".pth" files? Instead of having > some boiler-plate at the top of every file, you could specify your > paths there. I haven't thought about it enough to know that this idea > specifically is the best way to go, but it would be nice if there were > some way of solving this cleanly. I'm going to try to get our solution open-sourced, then I'll get your feedback on it. -- http://mail.python.org/mailman/listinfo/python-list
