Re: String formatting with the format string syntax
Andre Alexander Bell wrote: > On 09/14/2010 08:20 PM, Miki wrote: >> You can use ** syntax: > english = {'hello':'hello'} > s.format(**english) > > Thanks for your answer. Actually your answer tells me that my example > was misleading. Consider the template > > s = 'A template with {variable1} and {variable2} placeholders.' > > I'm seeking a way to extract the named placesholders, i.e. the names > 'variable1' and 'variable2' from the template. I'm not trying to put in > values for them. > > I hope this is clearer. >>> s = 'A template with {variable1} and {variable2} placeholders.' >>> [name for _, name, _, _ in s._formatter_parser() if name is not None] ['variable1', 'variable2'] Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
I think to do so either you will need to schedule a cron or write a daemon process which will run continuously. Assuming that its running only once a day or say timely manner daemon will be a costly affair for system resources To schedule crons for python, this might be useful (using yaml) http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml Thanks, Nitin On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > Hi Nitin,I need a python solution for that. > > > On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > >> are you looking for something like cron? >> >> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >> >>> Hi, >>> I have a python script running behind the scene,and I need it to call a >>> method on sunday 9 o'clock. >>> I get an idea,that I get the current time,and calculate the seconds to >>> sunday 9 o'clock, >>> then sleep these seconds and call my method,I think there could be an >>> elegant way to resolve this. >>> >>> Regards, >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> >> -- >> Nitin Pawar >> >> > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
Hi Nitin,I need a python solution for that. On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > are you looking for something like cron? > > On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > >> Hi, >> I have a python script running behind the scene,and I need it to call a >> method on sunday 9 o'clock. >> I get an idea,that I get the current time,and calculate the seconds to >> sunday 9 o'clock, >> then sleep these seconds and call my method,I think there could be an >> elegant way to resolve this. >> >> Regards, >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Nitin Pawar > > -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
are you looking for something like cron? On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > Hi, > I have a python script running behind the scene,and I need it to call a > method on sunday 9 o'clock. > I get an idea,that I get the current time,and calculate the seconds to > sunday 9 o'clock, > then sleep these seconds and call my method,I think there could be an > elegant way to resolve this. > > Regards, > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Nitin Pawar -- http://mail.python.org/mailman/listinfo/python-list
python call a procedure at the specified time
Hi, I have a python script running behind the scene,and I need it to call a method on sunday 9 o'clock. I get an idea,that I get the current time,and calculate the seconds to sunday 9 o'clock, then sleep these seconds and call my method,I think there could be an elegant way to resolve this. Regards, -- http://mail.python.org/mailman/listinfo/python-list
Re: can not import hashlib
Your python is compiled without md5. Maybe your system misses some libraries and you have to re-compile the python. On Wed, 15 Sep 2010 11:03:40 +0800 ch huang wrote: > i have a big problem,here is > and any can help me? > > Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) > [GCC 4.4.3 20100316 (prerelease)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import hashlib > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/hashlib.py", line 136, in > md5 = __get_builtin_constructor('md5') > File "/usr/lib/python2.6/hashlib.py", line 63, in > __get_builtin_constructor > import _md5 > ImportError: No module named _md5 > -- http://mail.python.org/mailman/listinfo/python-list
Re: Bit fields in python?
> Hi, > > I'm trying to use the construct library, but encountered a problem. May I > know how do I implement the following using the construct library? > > typedef struct > { > unsigned short size; > . > . > }CodecInfo; > > typedef struct > { > unsigned short size; > CodecInfo mastercodec; > CodecInfo slavecodec; > }StatusInfo; > > StatusInfo t; > printf("%hu %hu\n", t.mastercodec.size,t.slavecodec.size); > > Not sure how to include 2 copies of the CodecInfo Struct into StatusInfo > Struct & be able to access CodecInfo's fields like the example above: > > CodecInfo = Struct("CodecInfo", > . > . > . > ) > > StatusInfo = Struct("StatusInfo", > CodecInfo, > CodecInfo > ) > > Status = StatusInfo.parse(buf) > > You can just nest Struct objects. Here's one implementation of what you're looking for: from construct import * def make_codec_info(name): return Struct(name, ULInt16('size')) StatusInfo = Struct('StatusInfo', ULInt16('size'), make_codec_info('mastercodec'), make_codec_info('slavecodec'), ) c = StatusInfo.parse('\x12\x13\x01\x02\x03\x04') print c P.S. It is covered in the first part of construct's tutorial ( http://construct.wikispaces.com/tut-basics). The tutorial is a pretty good starting point for using construct. Eli -- http://mail.python.org/mailman/listinfo/python-list
can not import hashlib
i have a big problem,here is and any can help me? Python 2.6.5 (r265:79063, Apr 1 2010, 05:22:20) [GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/hashlib.py", line 136, in md5 = __get_builtin_constructor('md5') File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor import _md5 ImportError: No module named _md5 -- http://mail.python.org/mailman/listinfo/python-list
distutils, cygwin, 'not a regular file'
So, what is not a regular file about this? Is there any way to find out which files are being considered irregular? $ uname -a CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin $ cat setup.py from distutils.core import setup setup( name='xlsexport', version='0.3', py_modules=['xlsexport'] ) 20:47 pwatson [ pwatson:/cygdrive/c/Users/pwatson/bin/xlsexport] 12 $ python setup.py sdist running sdist warning: sdist: missing required meta-data: url warning: sdist: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied reading manifest file 'MANIFEST' creating xlsexport-0.3 making hard links in xlsexport-0.3... ' not a regular file -- skipping ' not a regular file -- skipping ' not a regular file -- skipping tar -cf dist/xlsexport-0.3.tar xlsexport-0.3 gzip -f9 dist/xlsexport-0.3.tar removing 'xlsexport-0.3' (and everything under it) -- http://mail.python.org/mailman/listinfo/python-list
This is Vegas - Get $2400 Free
This is Vegas - Get $2400 Free http://thisisvegas.com/get/a/179639 Click here to download over 400 Free Games http://thisisvegas.com/get/wd/206052 -- http://mail.python.org/mailman/listinfo/python-list
Re: palindrome iteration
Baba: > def i_palindrome(pal): > while len(pal)>1: > if pal[0] == pal[-1]: >pal=pal[1:-1] > return True > > print i_palindrome('annab') In normal programming a significant percentage of the time is spent debugging. Experience shows that even short functions may be buggy. If you don't want to waste too much time debugging your code you need to adopt a bit more rigorous approach to write programs. Learning to play piano requires a lot of self-discipline, programming too needs some. Ask yourself what are the exact purposes of your function/class/ program. And then define what are the correct outputs for all input corner cases you are able to find. This is TDD, Thought-driven development. For this program, what's the right output for mixed case strings, for empty strings, for input strings that contain many words with mixed white space and punctuation between them, for unicode strings that contain weird characters? Generally even simple functions may become very complex if you want to manage even complex input cases. You are free to ignore some of those inputs, to keep your code simple enough, but it's usually better for your function to not just ignore some inputs, but give some kind of error for the inputs you don't want to consider. Let's say you accept simple Unicode strings, you don't want to ignore white space, an empty string is palindrome, text cases need to be ignored. I don't like Test-Driven development a lot because your most powerful tool is your brain&mind and not your unit-tests, but I like tests a lot. So you need tests for this small function too. Here doctests are enough. Your first test is better to fail, to be sure your doctest is working: def is_palindrome(text): """ >>> is_palindrome("xy") False """ return True if __name__ == "__main__": import doctest doctest.testmod() print "Doctests done." Code formatting and function and argument names are important to keep code readable to yourself, improve its future maintenance, and reduce the total bug count. You may write this Python function in a high level style like this: def is_palidrome(text): ltext = text.lower() return ltext == ltext[::-1] But that doesn't teach you much programming, so for learning purposes you may try to create one function in lower-level style (that also doesn't stress the garbage collector, despite probably being overall slower in Python). So we use iterative loops and single char tests. But if you use a language as Scheme then a recursive solution too is a normal option. Now you need to invent the algorithm that solves your problem. Inventing algorithms that solve your problems is an art that requires training, experience and even ideas from this little book: http://en.wikipedia.org/wiki/How_to_Solve_It There are few ways to solve that problem, one possible way it to look at the first and last char of the string (ignoring their case), if they are different the given word is not palindrome, otherwise you look at the second and penultimate char, and you perform similar comparisons for all the char pairs. If your string length is odd there is no need to test the last char, but if you want to test it with itself because it keeps the code simpler it's not a problem. To avoid bugs like ones in your code you may think about the loop invariant and loop variant. This blog post shows an example to follow: http://reprog.wordpress.com/2010/04/25/writing-correct-code-part-1-invariants-binary-search-part-4a/ I use two indexes, i and j, that move forward and backwards in sync starting from the first and last char of the 'text' string. The program stops when they are on the same char or they cross. I have used an elaborate loop invariant, for this simple program it's overkill, but shows how you may do it. i ==><== j +--+--+--+--+--+--+--+--+--+ text | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ 0 1 2 3 4 5 6 7 8 def _is_palindrome_loop_invariant(i, j, length): assert i >= 0 assert i < length assert j >= 0 assert j < length assert i <= j assert i == length - 1 - j return True def is_palindrome(text): """ >>> is_palindrome("") True >>> is_palindrome("1") True >>> is_palindrome(u"x") True >>> is_palindrome("aa") True >>> is_palindrome("ab") False >>> is_palindrome("abc") False >>> [is_palindrome(s) for s in ["abA", "ABA", "ABA"]] [True, True, True] >>> is_palindrome("aibohphobia") True >>> is_palindrome("aibohphobia" * 1000) True >>> is_palindrome(list("aibohphobia")) True >>> is_palindrome([1, 2, 3]) Traceback (most recent call last): ... AttributeError: 'int' object has no attribute 'lower' """ n = len(text) i = 0 j = n - 1 while i < j: assert _is_palindrome_loop_invariant(i, j, n) if text[i].lower() != text[j].lower(): return
Re: Default python compile options
On Wed, Sep 15, 2010 at 10:20 AM, James Matthews wrote: > Thanks James, > I did try the plain old configure but I was missing compression zlib and I > wanted to make sure that I wasn't going to be be running in circles having > to run ./configure a bunch of times so I decided to ask) You might need to installed some other packages from Ubuntu/Debian eg: zlib-dev Building python requires certain "development libraries" that Ubuntu/Debian systems do not install by default (they are separate packages). cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list
Re: Default python compile options
Thanks James, I did try the plain old configure but I was missing compression zlib and I wanted to make sure that I wasn't going to be be running in circles having to run ./configure a bunch of times so I decided to ask) James On Tue, Sep 14, 2010 at 2:50 PM, James Mills wrote: > On Wed, Sep 15, 2010 at 7:25 AM, James Matthews > wrote: > > I am trying to compile Python 2.7 on Ubuntu and I am wondering what are > the > > default compile options (i.e ./configure ..) for ubuntu. I just want the > > standard ones that are included with the python2.6 version on ubuntu. Can > > someone please shed some light? > > You can easily find this out for yourself. > > Ubuntu is a Debian-based system. > > Use dpkg-source to get the source package of python-2.6 and have a > look at how it builds. > > cheers > James > > PS: There's nothing wrong with a plain old ./configure (no options). > > -- > -- James Mills > -- > -- "Problems are solved by method" > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com -- -- http://mail.python.org/mailman/listinfo/python-list
Numpy: Multiplying arrays of matrices
Suppose I have two N+2 dimensional arrays, representing N-d arrays of 2-d matrices. I want to perform matrix multiplication between corresponding matrices in these arrays. I had thought that dot() might do this, but it appears not, because e.g. applying it to two 3-d arrays gives a 4-d array, not another 3-d array. I'd also like to be able to find the inverse of each matrix in one of these arrays, but again, inv() doesn't do what I want -- it only works on 2-d arrays. Any thoughts on how to achieve these things using numpy functions? -- Greg -- http://mail.python.org/mailman/listinfo/python-list
webcam in gtalk/xmpp
Hi, I was wondering if there is an implementation in any of the xmpp python API (e.g. xmpppy, etc) that implements broadcasting webcam (as well as audio-chat). The documentation on xmpppy doesn't show me how this can be done. Is this even possible? Thanks Astan -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatting with the format string syntax
On 09/14/2010 08:20 PM, Miki wrote: You can use ** syntax: english = {'hello':'hello'} s.format(**english) Thanks for your answer. Actually your answer tells me that my example was misleading. Consider the template s = 'A template with {variable1} and {variable2} placeholders.' I'm seeking a way to extract the named placesholders, i.e. the names 'variable1' and 'variable2' from the template. I'm not trying to put in values for them. I hope this is clearer. Thanks again Andre -- http://mail.python.org/mailman/listinfo/python-list
Re: python27.exe vs python2.7.exe ...
On Wed, Sep 15, 2010 at 8:31 AM, Trent Mick wrote: > Hind sight is 20/20 is all I can say. :) Perhaps having 1/60 sight is better ? :) > When I added support for "pythonXY.exe" instead of "pythonX.Y.exe" I was > trying to add an out-of-the-box equivalent for what I saw some core > developers doing with their own batch scripts: py20.bat, py21.bat, etc. I > didn't think to provide equivalence to the Unix shortcuts. Also, this was a > looong time ago (back when python 1.5, 1.6 and 2.0 were still relevant) so > it could be there there *weren't* many of the typical (now) Linux > "pythonX.Y" installed executables. Good point :) My comment was just a comment, nothing negative intended! cheers james -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list
Re: python27.exe vs python2.7.exe ...
On 10-09-14 2:52 PM, James Mills wrote: On Wed, Sep 15, 2010 at 7:25 AM, Sridhar Ratnakumar wrote: Thoughts? I've never been a Windows developer (probably never will be), but I have one thought: Why has ActivePython not been doing this all along ? Hind sight is 20/20 is all I can say. :) When I added support for "pythonXY.exe" instead of "pythonX.Y.exe" I was trying to add an out-of-the-box equivalent for what I saw some core developers doing with their own batch scripts: py20.bat, py21.bat, etc. I didn't think to provide equivalence to the Unix shortcuts. Also, this was a looong time ago (back when python 1.5, 1.6 and 2.0 were still relevant) so it could be there there *weren't* many of the typical (now) Linux "pythonX.Y" installed executables. Trent -- Trent Mick ActiveState -- http://mail.python.org/mailman/listinfo/python-list
Re: python27.exe vs python2.7.exe ...
On Wed, Sep 15, 2010 at 7:25 AM, Sridhar Ratnakumar wrote: > Thoughts? I've never been a Windows developer (probably never will be), but I have one thought: Why has ActivePython not been doing this all along ? cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list
Re: Default python compile options
On Wed, Sep 15, 2010 at 7:25 AM, James Matthews wrote: > I am trying to compile Python 2.7 on Ubuntu and I am wondering what are the > default compile options (i.e ./configure ..) for ubuntu. I just want the > standard ones that are included with the python2.6 version on ubuntu. Can > someone please shed some light? You can easily find this out for yourself. Ubuntu is a Debian-based system. Use dpkg-source to get the source package of python-2.6 and have a look at how it builds. cheers James PS: There's nothing wrong with a plain old ./configure (no options). -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list
Re: scp with paramiko
Hello, On Wed, Sep 01, 2010 at 09:56:18AM -0700, cerr wrote: > I want to download a file from a client using > paramiko. I found plenty of ressources using > google on how to send a file but none that > would describe how to download files from a > client. Download files from remote to local? Get sftp object as usual, then e.g.: for f in sftp.listdir(rdir): lf = os.path.join(opts.tmpdir, f) sftp.get(rdir + "/" + f, lf) sftp.get() uses path + "/" + basename instead of os.path.join() because the latter uses local pathname conventions which may or may not be appropriate for remote system. -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
python27.exe vs python2.7.exe ...
Hi, As you may already know, ActivePython provides versioned Python executables that makes it possible to invoke a particular X.Y version from the command line directly if you have multiple Python versions on PATH. Eg: C:\Python27\python26.exe C:\Python27\python27.exe C:\Python31\python31.exe In the upcoming releases, we are considering to change this format to match the unix executables (with a 'dot' in it). Eg: C:\Python27\python2.6.exe C:\Python27\python2.7.exe C:\Python31\python3.1.exe The idea is to be able to invoke "python2.7 myscript.py" on both Unix and Windows. Thoughts? Because there is bin/python3 on unix (to separate it from the default 2.x interpreter) - it is perhaps a good idea to have "C:\Python31\python3.exe" as well. -srid -- http://mail.python.org/mailman/listinfo/python-list
Default python compile options
Hi, I am trying to compile Python 2.7 on Ubuntu and I am wondering what are the default compile options (i.e ./configure ..) for ubuntu. I just want the standard ones that are included with the python2.6 version on ubuntu. Can someone please shed some light? Thanks, James -- http://www.goldwatches.com -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross Compiling Python for ARM
On Tuesday 14 September 2010 21:19, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: >> # >> ./python >> >> -sh: ./python: not found > > > I'm guessing either there is no file ./python, or /bin/sh is fundamentally > broken. Yes, it may be instructive to use the file command to see what ./python actually is: file ./python David -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatting with the format string syntax
On Tue, Sep 14, 2010 at 3:20 PM, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Miki to exclaim: >> You can use ** syntax: >> >>> english = {'hello':'hello'} >> >>> s.format(**english) > > No, you can't. This only works with dicts, not with arbitrary mappings, or > dict subclasses that try to do some kind of funny stuff. > That was changed in 2.6 http://docs.python.org/release/2.6.6/whatsnew/2.6.html#other-language-changes -- http://mail.python.org/mailman/listinfo/python-list
Re: WMI in Python
On Sep 14, 7:46 am, KING LABS wrote: > On Sep 14, 10:39 am, KING LABS wrote: > > > > > > > > > > > On Sep 13, 8:31 pm, Jerry Hill wrote: > > > > On Mon, Sep 13, 2010 at 8:45 AM, KING LABS wrote: > > > > Hi All, > > > > > I am new to programming and python, Being a system administrator I > > > > have chose Inventory (Software & Hardware ) as my first project. > > > > You'll probably want to look at the python WMI > > > module:http://timgolden.me.uk/python/wmi/index.html > > > > as well as the pywin32 module:http://sourceforge.net/projects/pywin32/ > > > > IIRC, there's been quite a bit of discussion about inventorying > > > installed software on the pywin32 mailing > > > list:http://mail.python.org/mailman/listinfo/python-win32 > > > > -- > > > Jerry > > > Thank you all, I will go through the links provided and suggestions. > > Shall get back to you on this soon. > > The following information is exactly what I am trying to collect for > the inventory. I can find vb scripts with googling. I want to do the > same with Python & Win32. Use Server/Client architecture . > Client(agent) updates the information to server. > > > > BIOS: > > System serial number, manufacturer, and model > Bios manufacturer, version, and date > > Processors: > > Type, count (how many of them), manufacturer, speed, and cache > > Memory: > > Physical memory type, manufacturer, capacity, and slot number > Total physical memory > Total swap/paging memory > > Video: > > Video adapter: Chipset/model, manufacturer, memory size, speed, and > screen resolution > > Display monitor: Manufacturer, description, refresh rate, type, serial > number, and caption > > Storage/removable devices: > > Manufacturer, model, size, type, speed( all when applicable) > > Drive letter, filesystem type, partition/volume size, free space > > Network adapters/telephony: > > Manufacturer, model, type, speed, and description > MAC and IP address, mask and IP gateway, DHCP server used > > Miscellaneous hardware: > > Input devices: Keyboard, mouse, and pointing device > Sound devices: Manufacturer name, type, and description > System slots: Name, type, and designation > System ports: Type, name, caption, and description > > Software Information: ( from registry & add/remove program ) > > Operating system: Name, version, comments, and registration info > Installed software: Name, publisher, version (from Add / Remove > software or Programs and Features menu) > Custom-specified registry queries (applicable to Windows OS) > > -- when I found Python :-) I downloaded from a Ms site many (+- 120) py programs for hardware and os stuff and collated them into one script. Astonishing amount of data in the innards of a computer, do not print some of the...@#! I meant to wrap it in a neat menu (any time now), but it is easy to use as is. A few of the options : 102 --- -List Terminal Services Terminals- 103 --- -List Terminal Services Permissions- 104 --- -List Terminal Services Session Settings- 105 --- - List Terminal Services Session Directory Settings- 106 --- - List Terminal Services Network Adapter- 107 --- -List Terminal Services Environment Settings- 108 --- -List Terminal Services Logon Settings- 109 --- -List Terminal Services General Settings- 110 --- -List Terminal Services Client Settings- 111 --- -List Terminal Services Terminal Settings- 112 --- -List Terminal Service Service Properties- 113 --- -List Info about Binary Files used on Computer- 114 --- -List Info about CODECS on this computer- 115 --- -List Installed Software- 116 --- -List Installed Software Features- Happy to send to you, will post it somewhere soon. -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatting with the format string syntax
On Tuesday 14 September 2010, it occurred to Miki to exclaim: > You can use ** syntax: > >>> english = {'hello':'hello'} > >>> s.format(**english) No, you can't. This only works with dicts, not with arbitrary mappings, or dict subclasses that try to do some kind of funny stuff. > > On Sep 14, 9:59 am, Andre Alexander Bell wrote: > > Hello, > > > > I'm used to write in Python something like > > > > >>> s = 'some text that says: %(hello)s' > > > > and then have a dictionary like > > > > >>> english = { 'hello': 'hello' } > > > > and get the formatted output like this: > > > > >>> s % english > > > > Occasionally I want to extract the field names from the template string. > > I was used to write a class like > > > > class Extractor(object): > > def __init__(self): > > self.keys = [] > > def __getitem__(self, key): > > self.keys.append(key) > > return '' > > > > and use it like this: > > > > >>> e = Extractor() > > >>> res = s % e > > >>> e.keys > > ['hello'] > > > > Now Python has the format method for string formatting with the more > > advanced handling. So I could as well write > > > > >>> s = 'some text that says: {hello!s}' > > >>> s.format(hello='hello') > > > > My question is, if I do have a string template which uses the newer > > format string syntax, how do I best extract the field information? > > > > I found the str._formatter_parser() method which I could use like this: > > > > keys = [] > > for (a, key, c, d) in s._formatter_parser(): > > if key: > > keys.append(key) > > > > Is there a more elegant solution? > > What are a, c, d? > > Where can I find additional information on this method? > > Should one use a method that actually starts with an _? > > Couldn't this one change any time soon? > > > > Thanks for any help > > > > Andre -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross Compiling Python for ARM
On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim: > # > ./python > > -sh: ./python: not found I'm guessing either there is no file ./python, or /bin/sh is fundamentally broken. -- http://mail.python.org/mailman/listinfo/python-list
Cross Compiling Python for ARM
Hello, I've been working on an embedded ARM system which boots up quick (a beagleboard running a skinnied down version of Angstrom). For this I need to compile a lot of libraries from scratch. One of the things I need is Python; I've cross compiled Python and it works OK when I try to run it on an image on the same system which is more complete (the same hardware running Lucid Ubuntu). However when I try to run on the skinnied down image I get the following feedback: # ./python -sh: ./python: not found I'm guessing that Python is depending on some libraries which I don't have but as my situation is unusual I'm not sure what I am missing. So, I'm asking for help which is what libraries does python depend on on Linux? Thanks in advance. Cheers, Neil -- -- Neil Benn Msc Director Ziath Ltd Phone :+44 (0)7508 107942 Website - http://www.ziath.com IMPORTANT NOTICE: This message, including any attached documents, is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify Ziath Ltd immediately by email at i...@ziath.com. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatting with the format string syntax
You can use ** syntax: >>> english = {'hello':'hello'} >>> s.format(**english) On Sep 14, 9:59 am, Andre Alexander Bell wrote: > Hello, > > I'm used to write in Python something like > > >>> s = 'some text that says: %(hello)s' > > and then have a dictionary like > > >>> english = { 'hello': 'hello' } > > and get the formatted output like this: > > >>> s % english > > Occasionally I want to extract the field names from the template string. > I was used to write a class like > > class Extractor(object): > def __init__(self): > self.keys = [] > def __getitem__(self, key): > self.keys.append(key) > return '' > > and use it like this: > > >>> e = Extractor() > >>> res = s % e > >>> e.keys > ['hello'] > > Now Python has the format method for string formatting with the more > advanced handling. So I could as well write > > >>> s = 'some text that says: {hello!s}' > >>> s.format(hello='hello') > > My question is, if I do have a string template which uses the newer > format string syntax, how do I best extract the field information? > > I found the str._formatter_parser() method which I could use like this: > > keys = [] > for (a, key, c, d) in s._formatter_parser(): > if key: > keys.append(key) > > Is there a more elegant solution? > What are a, c, d? > Where can I find additional information on this method? > Should one use a method that actually starts with an _? > Couldn't this one change any time soon? > > Thanks for any help > > Andre -- http://mail.python.org/mailman/listinfo/python-list
String formatting with the format string syntax
Hello, I'm used to write in Python something like >>> s = 'some text that says: %(hello)s' and then have a dictionary like >>> english = { 'hello': 'hello' } and get the formatted output like this: >>> s % english Occasionally I want to extract the field names from the template string. I was used to write a class like class Extractor(object): def __init__(self): self.keys = [] def __getitem__(self, key): self.keys.append(key) return '' and use it like this: >>> e = Extractor() >>> res = s % e >>> e.keys ['hello'] Now Python has the format method for string formatting with the more advanced handling. So I could as well write >>> s = 'some text that says: {hello!s}' >>> s.format(hello='hello') My question is, if I do have a string template which uses the newer format string syntax, how do I best extract the field information? I found the str._formatter_parser() method which I could use like this: keys = [] for (a, key, c, d) in s._formatter_parser(): if key: keys.append(key) Is there a more elegant solution? What are a, c, d? Where can I find additional information on this method? Should one use a method that actually starts with an _? Couldn't this one change any time soon? Thanks for any help Andre -- http://mail.python.org/mailman/listinfo/python-list
Re: help removing pyQt dll from dist created with py2exe
many thanks Almar. No more pyqt stuff in my dist. cheers carlos On Tue, Sep 14, 2010 at 09:21, Almar Klein wrote: > Hi, > > Have you tried adding "PyQt4", "PyQt4.QtGui" and "PyQt4.QtCore" to your list > of excludes? > (Maybe only "PyQt4.QtGui" is sufficient.) > > Almar > > > On 14 September 2010 13:02, Carlos Grohmann > wrote: >> >> Hello all, >> >> i've been trying to build an .exe with py2exe. After many tentatives, >> it worked, but the total space used by the app goes to 30Mb. It is a >> simple app, that uses wxpython, matplotlib and numpy. I checked the >> library.zip file and notived that there is a pyQt-related file there: >> >> Pyqt - QtGui.pyo - 8 Mb >> >> I'm not using Qt at all, so I assume it would be safe to not have this >> file, but I don't see how to do it. >> >> my setup.py file follows. >> >> many thanks >> >> Carlos >> >> >> #-- >> from distutils.core import setup >> import py2exe >> from glob import glob >> >> # Remove the build folder, a bit slower but ensures that build >> contains the latest >> import shutil >> shutil.rmtree("build", ignore_errors=True) >> >> # my setup.py is based on one generated with gui2exe, so data_files is >> done a bit differently >> data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] >> >> includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', >> 'scrolledpanel', 'customtreectrl', >> 'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', >> 'wx.lib.wordwrap', 'types', >> 'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', >> 'matplotlib.figure', >> 'matplotlib.backends.backend_wxagg', >> 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', >> 'matplotlib.patches', 'matplotlib.lines', >> 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', >> 'matplotlib.collections', 'matplotlib.font_manager', >> 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' >> ] >> >> excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', >> 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', >> 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', >> 'sqlite3', >> 'bsddb', 'curses', 'email','_fltkagg', '_gtk', >> '_gtkcairo', >> '_agg2', '_cairo', '_cocoaagg', >> 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' >> ] >> >> packages = ['encodings','pytz','scipy'] >> >> dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', >> 'tcl84.dll', 'tk84.dll', >> 'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', >> 'libglib-2.0-0.dll', >> 'libcairo-2.dll', 'libpango-1.0-0.dll', >> 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', >> 'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', >> 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', >> 'QtCore4.dll' >> ] >> >> icon_resources = [] >> bitmap_resources = [] >> other_resources = [] >> >> # add the mpl mpl-data folder and rc file >> import matplotlib as mpl >> data_files += mpl.get_py2exe_datafiles() >> >> setup( >> windows=['OpenStereo.py'], >> # compressed and optimize reduce the size >> options = {"py2exe": {"compressed": 2, >> "optimize": 2, >> "includes": includes, >> "excludes": excludes, >> "packages": packages, >> "dll_excludes": dll_excludes, >> # using 2 to reduce number of files in dist >> folder >> # using 1 is not recommended as it often >> does not work >> "bundle_files": 2, >> "dist_dir": 'dist', >> "xref": False, >> "skip_archive": False, >> "ascii": False, >> "custom_boot_script": '', >> } >> }, >> >> # using zipfile to reduce number of files in dist >> zipfile = r'lib\library.zip', >> >> data_files=data_files >> ) >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- Prof. Carlos Henrique Grohmann - Geologist D.Sc. Institute of Geosciences - Univ. of São Paulo, Brazil http://www.igc.usp.br/pessoais/guano http://lattes.cnpq.br/5846052449613692 Linux User #89721 Can’t stop the signal. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with calling a static method in a private class
Diez B. Roggisch a écrit : lallous writes: How can I keep the class private and have the following work: [code] class __internal_class(object): @staticmethod def meth1(s): print "meth1:", s @staticmethod def meth2(s): print "meth2:", __internal_class.meth1(s) x = __internal_class() x.meth2('sdf') [/code] By not using a double underscore. It is effectless on classes anyway (they are not hidden because of that). FWIW, if what you want is to mark the class as being implementation (ie: not part of your module's API), just prefix it with a single underscore. And additionally, but simply not using staticmethods at all. +1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Install python-mcrypt on Ubuntu
On Tue, Sep 14, 2010 at 10:26 AM, lsolesen wrote: > > mcrypt.c:23:20: error: mcrypt.h: No such file or directory Well, there's your problem. You don't have the mcrypt headers installed. sudo apt-get install libmcrypt-dev -- http://mail.python.org/mailman/listinfo/python-list
Re: Install python-mcrypt on Ubuntu
Am 14.09.2010 16:26, schrieb lsolesen: > Tried on another machine, but with this error: > > lsole...@lsolesen-toshiba:~/Desktop/python-mcrypt-1.1$ python setup.py > install > running install > running build > running build_ext > building 'mcrypt' extension > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - > Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c > mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o > mcrypt.c:23:20: error: mcrypt.h: No such file or directory You are missing the development headers for mcrypt, too. sudo apt-get install libmcrypt-dev Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: help with calling a static method in a private class
lallous writes: > How can I keep the class private and have the following work: > > [code] > class __internal_class(object): > @staticmethod > def meth1(s): > print "meth1:", s > > @staticmethod > def meth2(s): > print "meth2:", > __internal_class.meth1(s) > > x = __internal_class() > > x.meth2('sdf') > [/code] By not using a double underscore. It is effectless on classes anyway (they are not hidden because of that). And additionally, but simply not using staticmethods at all. It's a rather obscure feature of python - usually, classmethods are what is considered a static method in other languages. And with that, even your double underscores work: class __internal_class(object): @classmethod def meth1(cls, s): print "meth1:", s @classmethod def meth2(cls, s): print "meth2:", cls.meth1(s) x = __internal_class() x.meth2('sdf') Diez -- http://mail.python.org/mailman/listinfo/python-list
help with calling a static method in a private class
How can I keep the class private and have the following work: [code] class __internal_class(object): @staticmethod def meth1(s): print "meth1:", s @staticmethod def meth2(s): print "meth2:", __internal_class.meth1(s) x = __internal_class() x.meth2('sdf') [/code] Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Install python-mcrypt on Ubuntu
Tried on another machine, but with this error: lsole...@lsolesen-toshiba:~/Desktop/python-mcrypt-1.1$ python setup.py install running install running build running build_ext building 'mcrypt' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o mcrypt.c:23:20: error: mcrypt.h: No such file or directory mcrypt.c:55: error: expected specifier-qualifier-list before ‘MCRYPT’ mcrypt.c:70: error: ‘MCRYPTObject’ has no member named ‘algorithm’ mcrypt.c:71: error: ‘MCRYPTObject’ has no member named ‘mode’ mcrypt.c: In function ‘catch_mcrypt_error’: mcrypt.c:86: warning: implicit declaration of function ‘mcrypt_strerror’ mcrypt.c:86: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ‘get_iv_from_obj’: mcrypt.c:110: error: ‘MCRYPTObject’ has no member named ‘iv_size’ mcrypt.c:110: warning: comparison between pointer and integer mcrypt.c:113: error: ‘MCRYPTObject’ has no member named ‘iv_size’ mcrypt.c:113: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘struct PyMemberDef *’ mcrypt.c: In function ‘check_algorithm’: mcrypt.c:130: warning: implicit declaration of function ‘mcrypt_list_algorithms’ mcrypt.c:130: warning: assignment makes pointer from integer without a cast mcrypt.c:134: warning: implicit declaration of function ‘mcrypt_free_p’ mcrypt.c: In function ‘check_mode’: mcrypt.c:147: warning: implicit declaration of function ‘mcrypt_list_modes’ mcrypt.c:147: warning: assignment makes pointer from integer without a cast mcrypt.c: In function ‘check_key’: mcrypt.c:171: warning: implicit declaration of function ‘mcrypt_enc_get_key_size’ mcrypt.c:171: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:180: warning: implicit declaration of function ‘mcrypt_enc_get_supported_key_sizes’ mcrypt.c:180: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:180: warning: assignment makes pointer from integer without a cast mcrypt.c:188: warning: implicit declaration of function ‘mcrypt_free’ mcrypt.c: In function ‘init_mcrypt’: mcrypt.c:208: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:208: warning: initialization makes integer from pointer without a cast mcrypt.c:225: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:225: warning: statement with no effect mcrypt.c:258: warning: implicit declaration of function ‘mcrypt_enc_set_state’ mcrypt.c:258: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:258: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:259: error: ‘MCRYPTObject’ has no member named ‘iv_size’ mcrypt.c:261: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:261: warning: statement with no effect mcrypt.c:263: warning: implicit declaration of function ‘mcrypt_generic_deinit’ mcrypt.c:263: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:266: warning: implicit declaration of function ‘mcrypt_generic_init’ mcrypt.c:266: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:267: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:268: error: ‘MCRYPTObject’ has no member named ‘init_key_size’ mcrypt.c:269: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:271: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:271: warning: statement with no effect mcrypt.c:272: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:273: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:274: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:274: warning: statement with no effect mcrypt.c:275: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:275: warning: statement with no effect mcrypt.c:276: error: ‘MCRYPTObject’ has no member named ‘init_key_size’ mcrypt.c:276: warning: statement with no effect mcrypt.c:279: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:279: warning: statement with no effect mcrypt.c:282: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:282: warning: statement with no effect mcrypt.c:283: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:284: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:285: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:285: warning: statement with no effect mcrypt.c:286: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:286: warning: statement with no effect mcrypt.c:287: error: ‘MCRYPTObject’ has no member named ‘init_key_size’ mcrypt.c:287: warning: statement with no effect mcrypt.c:290: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:297: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:297: warning: statement with no effect mcrypt.c:298: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:302: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:303: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:303: error: ‘MCRYPTObject’
Re: Install python-mcrypt on Ubuntu
Am 14.09.2010 16:14, schrieb lsolesen: > I am trying to install python-mcrypt (http://labix.org/python-mcrypt) > on Ubuntu, but I cannot get it to work. I have the following python > installed: sudo apt-get install python-dev Christian -- http://mail.python.org/mailman/listinfo/python-list
Install python-mcrypt on Ubuntu
I am trying to install python-mcrypt (http://labix.org/python-mcrypt) on Ubuntu, but I cannot get it to work. I have the following python installed: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 I get the following message when trying to install. lsole...@lsolesen-lenovo:~/Desktop/python-mcrypt-1.1$ python setup.py install running install running build running build_ext building 'mcrypt' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -DVERSION="1.1" -I/usr/include/python2.6 -c mcrypt.c -o build/temp.linux-i686-2.6/mcrypt.o mcrypt.c:24:20: error: Python.h: No such file or directory mcrypt.c:25:26: error: structmember.h: No such file or directory mcrypt.c:39: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token mcrypt.c:43: error: ‘NULL’ undeclared here (not in a function) mcrypt.c:54: error: expected specifier-qualifier-list before ‘PyObject_HEAD’ mcrypt.c:69: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘MCRYPT_members’ mcrypt.c:75: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’ mcrypt.c: In function ‘catch_mcrypt_error’: mcrypt.c:89: warning: implicit declaration of function ‘strdup’ mcrypt.c:89: warning: incompatible implicit declaration of built-in function ‘strdup’ mcrypt.c:90: warning: implicit declaration of function ‘strlen’ mcrypt.c:90: warning: incompatible implicit declaration of built-in function ‘strlen’ mcrypt.c:92: warning: implicit declaration of function ‘PyErr_SetString’ mcrypt.c:92: error: ‘MCRYPTError’ undeclared (first use in this function) mcrypt.c:92: error: (Each undeclared identifier is reported only once mcrypt.c:92: error: for each function it appears in.) mcrypt.c:93: warning: implicit declaration of function ‘free’ mcrypt.c:93: warning: incompatible implicit declaration of built-in function ‘free’ mcrypt.c: At top level: mcrypt.c:103: error: expected declaration specifiers or ‘...’ before ‘PyObject’ mcrypt.c: In function ‘get_iv_from_obj’: mcrypt.c:105: error: ‘ivobj’ undeclared (first use in this function) mcrypt.c:105: error: ‘Py_None’ undeclared (first use in this function) mcrypt.c:107: warning: implicit declaration of function ‘PyString_Check’ mcrypt.c:108: warning: implicit declaration of function ‘PyString_Size’ mcrypt.c:109: warning: implicit declaration of function ‘PyString_AsString’ mcrypt.c:110: error: ‘MCRYPTObject’ has no member named ‘iv_size’ mcrypt.c:111: warning: implicit declaration of function ‘PyErr_Format’ mcrypt.c:111: error: ‘PyExc_ValueError’ undeclared (first use in this function) mcrypt.c:113: error: ‘MCRYPTObject’ has no member named ‘iv_size’ mcrypt.c:117: error: ‘PyExc_TypeError’ undeclared (first use in this function) mcrypt.c: In function ‘check_algorithm’: mcrypt.c:133: warning: implicit declaration of function ‘strcmp’ mcrypt.c: In function ‘check_key’: mcrypt.c:167: error: ‘PyExc_ValueError’ undeclared (first use in this function) mcrypt.c:171: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:180: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c: In function ‘init_mcrypt’: mcrypt.c:208: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:225: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:230: error: ‘MCRYPTError’ undeclared (first use in this function) mcrypt.c:258: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:258: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:259: error: ‘MCRYPTObject’ has no member named ‘iv_size’ mcrypt.c:261: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:263: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:266: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:267: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:268: error: ‘MCRYPTObject’ has no member named ‘init_key_size’ mcrypt.c:269: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:271: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:272: warning: implicit declaration of function ‘PyMem_Free’ mcrypt.c:272: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:273: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:274: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:275: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:276: error: ‘MCRYPTObject’ has no member named ‘init_key_size’ mcrypt.c:279: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:282: error: ‘MCRYPTObject’ has no member named ‘init’ mcrypt.c:283: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:284: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:285: error: ‘MCRYPTObject’ has no member named ‘init_iv’ mcrypt.c:286: error: ‘MCRYPTObject’ has no member named ‘init_key’ mcrypt.c:287: error: ‘MCRYPTObject’ has no member named ‘init_key_size’ mcrypt.c:290: error: ‘MCRYPTObject’ has no member named ‘thread’ mcrypt.c:297: error: ‘MCRYPTObject’ has no
Re: Expected bahaviour of os.chroot and os.getcwd
On 14/09/10 11:19, Nobody wrote: On Mon, 13 Sep 2010 19:04:53 +0100, r0g wrote: i.e. So do I always have to change directory after changing into a chroot? You don't *have* to change the directory, but not doing so probably defeats the point of performing a chroot(). Thanks for the info 'Nobody', that was really clear and helpful :) It's kinda obvious once it's pointed out I suppose, the docs for the os module are primarily the os's own docs, should have thought to check the manpages eh, duh! Thanks very much for getting back to me, Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: help removing pyQt dll from dist created with py2exe
Hi, Have you tried adding "PyQt4", "PyQt4.QtGui" and "PyQt4.QtCore" to your list of excludes? (Maybe only "PyQt4.QtGui" is sufficient.) Almar On 14 September 2010 13:02, Carlos Grohmann wrote: > Hello all, > > i've been trying to build an .exe with py2exe. After many tentatives, > it worked, but the total space used by the app goes to 30Mb. It is a > simple app, that uses wxpython, matplotlib and numpy. I checked the > library.zip file and notived that there is a pyQt-related file there: > > Pyqt - QtGui.pyo - 8 Mb > > I'm not using Qt at all, so I assume it would be safe to not have this > file, but I don't see how to do it. > > my setup.py file follows. > > many thanks > > Carlos > > > #-- > from distutils.core import setup > import py2exe > from glob import glob > > # Remove the build folder, a bit slower but ensures that build > contains the latest > import shutil > shutil.rmtree("build", ignore_errors=True) > > # my setup.py is based on one generated with gui2exe, so data_files is > done a bit differently > data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] > > includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', > 'scrolledpanel', 'customtreectrl', >'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', > 'wx.lib.wordwrap', 'types', >'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', > 'matplotlib.figure', >'matplotlib.backends.backend_wxagg', > 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', >'matplotlib.patches', 'matplotlib.lines', > 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', >'matplotlib.collections', 'matplotlib.font_manager', > 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' >] > > excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', >'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', >'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', > 'sqlite3', >'bsddb', 'curses', 'email','_fltkagg', '_gtk', > '_gtkcairo', >'_agg2', '_cairo', '_cocoaagg', > 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' >] > > packages = ['encodings','pytz','scipy'] > > dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', > 'tcl84.dll', 'tk84.dll', >'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', > 'libglib-2.0-0.dll', >'libcairo-2.dll', 'libpango-1.0-0.dll', > 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', >'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', > 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', >'QtCore4.dll' >] > > icon_resources = [] > bitmap_resources = [] > other_resources = [] > > # add the mpl mpl-data folder and rc file > import matplotlib as mpl > data_files += mpl.get_py2exe_datafiles() > > setup( >windows=['OpenStereo.py'], > # compressed and optimize reduce the size >options = {"py2exe": {"compressed": 2, > "optimize": 2, > "includes": includes, > "excludes": excludes, > "packages": packages, > "dll_excludes": dll_excludes, > # using 2 to reduce number of files in dist > folder > # using 1 is not recommended as it often > does not work > "bundle_files": 2, > "dist_dir": 'dist', > "xref": False, > "skip_archive": False, > "ascii": False, > "custom_boot_script": '', > } > }, > ># using zipfile to reduce number of files in dist >zipfile = r'lib\library.zip', > >data_files=data_files > ) > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
help removing pyQt dll from dist created with py2exe
Hello all, i've been trying to build an .exe with py2exe. After many tentatives, it worked, but the total space used by the app goes to 30Mb. It is a simple app, that uses wxpython, matplotlib and numpy. I checked the library.zip file and notived that there is a pyQt-related file there: Pyqt - QtGui.pyo - 8 Mb I'm not using Qt at all, so I assume it would be safe to not have this file, but I don't see how to do it. my setup.py file follows. many thanks Carlos #-- from distutils.core import setup import py2exe from glob import glob # Remove the build folder, a bit slower but ensures that build contains the latest import shutil shutil.rmtree("build", ignore_errors=True) # my setup.py is based on one generated with gui2exe, so data_files is done a bit differently data_files = [("Microsoft.VC90.CRT", glob(r'c:\dev\*.*'))] includes = ['wx', 'os', 'sys', 'csv', 're', 'floatspin', 'scrolledpanel', 'customtreectrl', 'wx.lib.expando', 'wx.lib.pubsub', 'wx.lib.embeddedimage', 'wx.lib.wordwrap', 'types', 'matplotlib', 'matplotlib.pyplot', 'matplotlib.axes', 'matplotlib.figure', 'matplotlib.backends.backend_wxagg', 'mpl_toolkits.axes_grid.axislines', 'mpl_toolkits.axes_grid', 'matplotlib.patches', 'matplotlib.lines', 'matplotlib.text', 'matplotlib.mlab', 'matplotlib.nxutils', 'matplotlib.collections', 'matplotlib.font_manager', 'numpy', 'numpy.ma', 'numpy.linalg', 'math', 'scipy.interpolate' ] excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter', 'pydoc', 'doctest', 'test', 'sqlite3', 'bsddb', 'curses', 'email','_fltkagg', '_gtk', '_gtkcairo', '_agg2', '_cairo', '_cocoaagg', 'matplotlib.backends.backend_qt4agg','matplotlib.backends.backend_qt4' ] packages = ['encodings','pytz','scipy'] dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'libgdk_pixbuf-2.0-0.dll', 'libgtk-win32-2.0-0.dll', 'libglib-2.0-0.dll', 'libcairo-2.dll', 'libpango-1.0-0.dll', 'libpangowin32-1.0-0.dll', 'libpangocairo-1.0-0.dll', 'libglade-2.0-0.dll', 'libgmodule-2.0-0.dll', 'libgthread-2.0-0.dll', 'QtGui4.dll', 'QtCore.dll', 'QtCore4.dll' ] icon_resources = [] bitmap_resources = [] other_resources = [] # add the mpl mpl-data folder and rc file import matplotlib as mpl data_files += mpl.get_py2exe_datafiles() setup( windows=['OpenStereo.py'], # compressed and optimize reduce the size options = {"py2exe": {"compressed": 2, "optimize": 2, "includes": includes, "excludes": excludes, "packages": packages, "dll_excludes": dll_excludes, # using 2 to reduce number of files in dist folder # using 1 is not recommended as it often does not work "bundle_files": 2, "dist_dir": 'dist', "xref": False, "skip_archive": False, "ascii": False, "custom_boot_script": '', } }, # using zipfile to reduce number of files in dist zipfile = r'lib\library.zip', data_files=data_files ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting an ugly path to a shell path
On Tue, 14 Sep 2010 01:07:48 +0200, AmFreak wrote: > im using a QFileDialog to let the user select a path that is used later in > a command send to the shell like this: > > retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr = > PIPE) > > The problem that occurs now is when the user selects an "ugly" path like > this /home/user/!" §$/. > The shell don't understand the special chars so i have to escape them with > "\" . Is there some fundamental reason why you're using a shell? Most of the time, you're better off executing the command directly, i.e.: process = Popen([command, path], shell=False, ...) If you must "unparse" the path for the benefit of the shell, the first question is: *which* shell? For a typical Bourne shell, quoting a string using: qstring = r"'" + string.replace(r"'", r"'\''") + r"'" should be reliable. This won't work for Windows, though; look at the source code for the subprocess module for the (rather bizarre) quoting rules used by Windows. -- http://mail.python.org/mailman/listinfo/python-list
python tkinter Listbox
Hi all, I am building a simple tool using tkinter,and need multiselection checklist.I find that Listbox with option selectmode=tkinter.MULTIPLE could do this for me. But when I have two Listboxs,I do some selection with one,then do selection with another one,the previous listbox get cleared.I wonder how to keep the previous listbox selected. Wish I explained clear. Regards. -- http://mail.python.org/mailman/listinfo/python-list
Re: Expected bahaviour of os.chroot and os.getcwd
On Mon, 13 Sep 2010 19:04:53 +0100, r0g wrote: > i.e. So do I always have to change directory after changing into a chroot? You don't *have* to change the directory, but not doing so probably defeats the point of performing a chroot(). > The reason I ask is because an app I was running inside the chrooted > environment (specifically: apt-get) was trying to access files outside > the chroot and erroring when it couldn't. I figured it must be doing a > getcwd() and getting the cwd of the script that initialized the chroot. > I just wanted to confirm that's how it's supposed to work so I'd > appreciate it if anyone either knows or can point me to the docs that > explain in more detail than http://docs.python.org/library/os.html See the relevant manpages. os.chroot, os.chdir and os.getcwd are relatively thin interfaces to the underlying OS functions. > Also, out of curiosity... If it does work (and should work) the way I > think it does how come os.chroot doesn't set the cwd to "/" for you? Because os.chroot just calls the OS' chroot(), which doesn't perform an implicit chdir(). I don't know whether there is any deep reason for the behaviour (beyond the Unix philosophy of "do what I say, not what you think I mean"), but it's been that way forever and isn't likely to change. > It's not a costly operation and it could prevent errors of ignorance > such as my own. Are there any good reasons why a person (who isn't a > hacker / cracker / kludger) would want chrooted processes to be able to > see the calling script's cwd anyway? Maybe I'm having a failure of > imagination today but the only things I can think that info could be > useful for are jailbreaking, nefarious reconnaissance and real ugly > hacks. Maybe someone here can enlighten me :) chroot() wasn't designed as a security mechanism. It simply allows you to control a parameter of the filename resolution algorithm (i.e. the root directory). If you want to use it as a security mechanism, you have to perform additional work, i.e. ensuring that there are no other ways of escaping the chroot (cwd, descriptors, etc). Oh, and you need to lose the ability to perform a further chroot (root privilege or CAP_SYS_CHROOT), otherwise you can just do e.g.: os.chdir("/") os.mkdir("foo") os.chroot("foo") os.chdir("..") Making Python's os.chroot() call os.chdir() wouldn't help from a security standpoint, as the code can still achieve the "raw" behaviour with e.g. ctypes or os.system("chroot ..."). -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting an ugly path to a shell path
In message , amfr...@web.de wrote: > The shell don't understand the special chars so i have to escape them with > "\" . > Is there a function that does this ? You could get the shell (at least if it’s Bash) itself to do this. Try the following script: import sys import os import subprocess os.environ["ARG1"] = sys.argv[1] sys.stdout.write \ ( subprocess.Popen ( args = "printf $'%q\\n' \"$ARG1\"", stdout = subprocess.PIPE, shell = True ).communicate()[0] ) Sample output: l...@theon:hack> ./escape_try '\ & # *' \&\ #\ \* -- http://mail.python.org/mailman/listinfo/python-list
Re: python datetime
Thank you,the timedelta class is awesome. On Tue, Sep 14, 2010 at 3:50 PM, Michael Ricordeau < michael.ricord...@gmail.com> wrote: > > # Determine diff days between two dates > import datetime > now = datetime.date(2010, 9, 28) > next = datetime.date(2010, 10, 5) > delta = next - now > > #delta is datetime.timedelta type. > #(You can extract days diff) > > # Determine date in 7 days > import datetime > now = datetime.date(2010, 9, 28) > delta = datetime.timedelta(days=7) > next = now + delta > > > > > > > > > > > Le Tue, 14 Sep 2010 14:41:09 +0800, > Von a écrit : > > > Hi, > > How to determine a date is just the 7th day after today > > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the > > 7th day is 5 Oct,is there simple way to do this work? > > I wish I explained clear > > > > Bests, > -- http://mail.python.org/mailman/listinfo/python-list
Re: python datetime
# Determine diff days between two dates import datetime now = datetime.date(2010, 9, 28) next = datetime.date(2010, 10, 5) delta = next - now #delta is datetime.timedelta type. #(You can extract days diff) # Determine date in 7 days import datetime now = datetime.date(2010, 9, 28) delta = datetime.timedelta(days=7) next = now + delta Le Tue, 14 Sep 2010 14:41:09 +0800, Von a écrit : > Hi, > How to determine a date is just the 7th day after today > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the > 7th day is 5 Oct,is there simple way to do this work? > I wish I explained clear > > Bests, -- http://mail.python.org/mailman/listinfo/python-list
Re: python datetime
Von wrote: > How to determine a date is just the 7th day after today > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the 7th day is 5 Oct,is there simple way to do this work? > I wish I explained clear The datetime module takes care of this >>> import datetime as dt >>> dt.date(2010, 9, 28) + dt.timedelta(days=7) datetime.date(2010, 10, 5) See http://docs.python.org/library/datetime.html Why didn't you find that yourself? It's the first match if you google for python datetime. Peter -- http://mail.python.org/mailman/listinfo/python-list
python datetime
Hi, How to determine a date is just the 7th day after today ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the 7th day is 5 Oct,is there simple way to do this work? I wish I explained clear Bests, -- http://mail.python.org/mailman/listinfo/python-list