pytemplate: template for python developers
Hello, I'm pleased to announce the new release (1.5) of pytemplate project, major step in its young life. pytemplate project is a framework helping python developers at starting their program with a lightweight template, managing basic options like configuration file, logging, daemon capabilities, signal management. I believe that this project is able to help to bring development quality and speed leverage to a lot of small programs. Until a maybe wise introduction in a python release as a built-in module, the best way to use it is to introduce the source file itself in your program. You only have to import the module. You will be able to find usage examples, to download sources at http://www.bulot.org/wiki/doku.php?id=projects:python:pytemplate, wiki page of the project. Do not hesitate to give me your feedback on the concept itself on the program usage, and on its implementation. I would be glad to share this project to improve it. Things that have be done soon: -Windows platform testing (not done). I'm not sure about daemon methodology and signal management. -Python 3 portability. As far as I know, it should not be to much work. Best regards. Stephane -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
web2py 1.56.4
web2py 1.56.4 is out http://www.web2py.com What is web2py? = - It is the web framework used by PyCon 2009 for registration. - It a very easy and very powerful Python web framework. - It is fast and rock solid. It has a very clean design and it is strong on security. - Includes a web based development environment, maintenance environment, and database administrative interface. - Includes a Database Abstraction Layer that works with SQLite, MySQL, PostgreSQL, FireBird, MSSQL, Oracle, AND the Google App Engine. The DAL does migrations. - Includes a pure Python based template language with no indentation requirements. - Includes jQuery, simplejson, markdown, feedparser, PyRSS2, nicEdit, EditArea and a lot more. - Runs on any platform that runs python. The binary versions can even run off a USB drive without dependences. - The same apps can run on a PC with Oracle or on the Google App Engine or on Windows Mobile, without changes, including DB API. New features In 1.56.4: = - Bugs fixes in docs and new authentication API New features In 1.56: = - Authentication - Authorization (Role Based Access Controller) - CRUD - portable url fetch function - portable geocoding function - PEP8 compliant - Python 2.5 - Runs on Jython (although without db drivers) - Runs on IronPython (although without CSV, db drivers and internal web-server) - DAL shortcuts - SQLFORM has default image preview - new generic.html view - more examples and documentation - always backward compatible Example of code = ## in model db.py from gluon.tools import * db=SQLDB('sqlite://storage.db') db.define_table('puppy', db.Field('name'), db.Field('image','upload')) auth=Auth(globals(),db) auth.define_tables() crud=Crud(globals(),db) ## in controller default.py def user(): to expose register, login, logout, etc return dict(form=auth()) @auth.requires_login() def data(): to expose select, create, update, delete, etc return dict(form=crud()) @auth.requires_login() def download(): for downloading uploaded images return response.download(request,db) ## in view default/user.html {{extend 'layout.html'}} div{{=form}}/div ## in view default/data.html {{extend 'layout.html'}} div{{=form}}/div This code will allow to register, login, change password, upload images of puppies (with relative names), select puppies, edit records, read and preview images, enforce authorization, and more. Thanks to all the contributors: === * Attila Csipa (cron job) * Bill Ferrett (modular DAL design) * CJ Lazell (tester) * DenesL (validators) * Douglas Andrade (2.6 compliance, docstrings) * Francisco Gama (bug fixing) * Fran Boon (authorization and authentication) * Fred Yanowski (XHTML compliance) * Jonathan Benn (is_url validator and tests) * Jose Jachuf (Firebird support) * Kyle Smith (javascript) * Limodou (winservice) * Marcel Leuthi (Oracle support) * Mark Larsen (taskbar widget) * Mark Moore (databases and daemon scripts) * Markus Gritsch (bug fixing) * Martin Hufsky (expressions in DAL) * Mateusz Banach (stickers) * Michael Willis (shell) * Nathan Freeze (admin design) * Niall Sweeny (MSSQL support) * Niccolo Polo (epydoc) * Ondrej Such (MSSQL support) * Pai (internationalization) * Phyo Arkar Lwin (web hosting and Jython tester) * Robin Bhattacharyya (Google App Engine support) * Sharriff Aina (tester and PyAMF integration) * Sterling Hankins (tester) * Stuart Rackham (MSSQL support) * Telman Yusupov (Oracle support) * Timothy Farrell (python 2.6 compliance, windows support) * Yarko Tymciurak (design) * Younghyun Jo (internationalization) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Pydev 1.4.4 Released
Hi All, Pydev and Pydev Extensions 1.4.4 have been released -- note that the release already happened 4 days ago... :) Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev: -- This release fixes a critical bug when configuring the interpreter (if no environment variables were specified, it was not possible to configure an interpreter) What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny -- Software Developer Aptana http://aptana.com/python Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: bool evaluations of generators vs lists
On 2009-02-10, Albert Hopkins mar...@letterboxes.org wrote: On Tue, 2009-02-10 at 12:50 -0800, Josh Dukes wrote: I don't understand what you mean by this. But if you really want to know if a generator is non-empty: def non_empty(virgin_generator): try: virgin_generator.next() # note you just lost the first value return True except StopIteration: return False The only way to get around this is to put all the values of a generator inside a container (e.g. a list): l = list(generator_object) but in doing so you've (obviously) lost the advantages of the generator. Well he could always use a wrapper like the following: nothing = object() class BoolIterator (object): def __init__(self, iter): self.iter = iter self.value = nothing self.item = nothing def __iter__(self): return (self) def __nonzero__(self): if self.value is nothing: try: self.item = self.iter.next() self.value = True return True except StopIteration: self.value = False return False else: return self.value def next(self): if self.item is not nothing: result = self.item self.item = nothing return result if self.value is not nothing: return self.iter.next() else: try: result = self.iter.next() self.value = True return result except StopIteration: self.value = False raise it1 = BoolIterator(i for i in xrange(10)) for i in it1: print i it2 = BoolIterator(i for i in xrange(10)) if it2: print item found for i in it2: print i else: print problem it3 = BoolIterator(i for i in xrange(0)) if it3: print problem else: print it3 is empty -- http://mail.python.org/mailman/listinfo/python-list
Re: How does one get from ImportError: DLL load failed:... to a culprit .dll and symbol?
My reading of the Python 2.6.1 version of dynload_win.c tells me that: 1. It uses LoadLibraryEx() to attempt to load the pyd given its full pathname 2. If that fails, it gets the Windows error code using GetLastError() 3. It gets the Windows message text using FormatMessage() 4. It assembles the message as DLL load failed: plus the Windows message text (less any trailing \r\n). Note that if the pyd load succeeds, it rummages in memory to find the pythonxx.dll used by the pyd so that it can be checked for consistency. Then and only then it uses GetProcAddress() to get the address of the initFOO function. Do you know a way of getting more info out of Windows than GetLastError ()? Thank you for your help, it is much appreciated: In summary: Q) How can one get Python to tell you which symbol is causing a problem when it loads an extension with a bad reference to a symbol in a DLL it uses? A) There is no such way: you *must* use external tools: When a symbol is missing form a DLL that a Python extension depends on, the failure will be picked up in Python immediately on attempting to load the extension: the extension code is never reached and there is no specific attempt made in Python to resolve the problem symbol. further, The normal platform APIs lack the ability to determine the cause of the load failure. Do you know a way of getting more info out of Windows than GetLastError ()? No, but presumably the ability to determine in code that a DLL has a bad reference and which symbol is bad exists because the depends program is able to do it. Of course it's a separate question as to whether Python wants to load itself down with complex platform specific code for a small corner case. Best Regards, Chris. -- http://mail.python.org/mailman/listinfo/python-list
Re: read csv error question
On Feb 24, 10:42 am, rdmur...@bitdance.com wrote: Vincent Davis vinc...@vincentdavis.net wrote: I am trying to read a csv file from excel on a mac. I get the following error.SystemExit: file some.csv, line 1: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? I was using the example code import csv, sys reader = csv.reader(open('/Volumes/vincentdavis 2/match/data/matchdata2008.csv', rb)) try: for row in reader: print row except csv.Error, e: sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e)) I think this has to do with the end of line character but I am unsure how to fix it. I don't what to change the actual csv file I would like to fix the code. You could try reading the error message and looking at the documentation of the 'open' function. Pay particular attention to the keywords 'universal-newline mode'. Hint: 'rb' is almost the opposite of universal newline mode, and it is very rare that you'd want to use 'b' to read a text file. --RDM A CSV file is *NOT* a text file. See the module docs. Also see this: http://bugs.python.org/issue4847 -- http://mail.python.org/mailman/listinfo/python-list
Re: opening files with names in non-english characters.
En Tue, 24 Feb 2009 01:29:07 -0200, venutaurus...@gmail.com venutaurus...@gmail.com escribió: First of all thanks for your response. I've written a function as shown below to recurse a directory and return a file based on the value of n. I am calling this fucntion from my main code to catch that filename. The folder which it recurses through contains a folder having files with unicode names (as an example i've given earlier. --- def findFile(dir_path): for name in os.listdir(dir_path): full_path = os.path.join(dir_path, name) print full_path if os.path.isdir(full_path): findFile(full_path) Here, you're simply discarding the result from the recursive call. Try something like this: result = findFile(full_path) if result is not None: return result else: n = n - 1 if(n ==0): return full_path --- Now, what happens if you forget about findFile and try with a direct name instead? fpath = rE:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_ÍÎIÐNOKÔÕÖ×ØUÚÛÜUUßaáâãäåæicéeëeíîidnokôõö÷øuúûüuu.txt.txt st = os.stat(path) print st -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Reference or Value?
Steven D'Aprano wrote: On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: Steven D'Aprano wrote: On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: as far as i understand things, the best model is: 1 - everything is an object 2 - everything is passed by reference Except that is wrong. If it were true, you could do this: [pointer swapping] i was thinking of how the stack is used; i would have called what you are talking about pointer semantics. however, on reading around a little, it seems that i'm in a very small minority (which is a pity, because if you restrict the meaning to how values are handled on the stack then you get a lot closer to having just values and references, rather than the whole pile of different terms that are apparently in use). sorry for the confusion, Why is it a pity to have a whole pile of different terms to describe a whole lot of different behaviours? I would suggest the real confusion would be if we had two terms to describe a dozen different parameter- passing conventions. because: (1) it's often useful to explain things as (simpler) orthogonal components rather than globbing everything under one term; that lets you more easily carry across knowledge from previous experience. (2) while using a term that has (according to wikipedia) widespread usage in the Python community helps you save time and avoid confusion, it doesn't necessarily explain best to someone from outside that community what is happening. in this particular case you are getting dangerously close to having a term that is used only for one language and which, therefore, is at risk of meaning little more that the way python does it (which is, i think you'll agree, more tautological than helpful). andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem in accessing files with unicode fonts.
En Tue, 24 Feb 2009 05:15:33 -0200, venu madhav venutaurus...@gmail.com escribió: def findFile(dir_path): for name in os.listdir(dir_path): full_path = os.path.join(dir_path, name) print full_path if os.path.isdir(full_path): findFile(full_path) else: v = unicode(full_path,errors='skip') i = win32api.GetFileAttributes(v) findFile(F:\\DataSet\\Unicode) --- Now when I run this scirpt, the full_path variable which should contain the name of the file has for non english ( I tried Arabic) characters. As a result the getfileattributes function is failing to recognise that file and is raising an exception. i = win32api.GetFileAttributes(v) error: (123, 'GetFileAttributes', 'The filename, directory name, or volume label syntax is incorrect.') If you call os.listdir with an unicode directory, it returns unicode file names. That is (after correcting the previous error in findFile), call it using: findFile(uF:\\DataSet\\Unicode) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem in accessing files with unicode fonts.
On Feb 24, 1:44 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 24 Feb 2009 05:15:33 -0200, venu madhav venutaurus...@gmail.com escribió: def findFile(dir_path): for name in os.listdir(dir_path): full_path = os.path.join(dir_path, name) print full_path if os.path.isdir(full_path): findFile(full_path) else: v = unicode(full_path,errors='skip') i = win32api.GetFileAttributes(v) findFile(F:\\DataSet\\Unicode) --- Now when I run this scirpt, the full_path variable which should contain the name of the file has for non english ( I tried Arabic) characters. As a result the getfileattributes function is failing to recognise that file and is raising an exception. i = win32api.GetFileAttributes(v) error: (123, 'GetFileAttributes', 'The filename, directory name, or volume label syntax is incorrect.') If you call os.listdir with an unicode directory, it returns unicode file names. That is (after correcting the previous error in findFile), call it using: findFile(uF:\\DataSet\\Unicode) -- Gabriel Genellina Thank you for your solution. It really helped. But how should I give if my path is in a varialble. For ex: path has that value obtained through command line arguments. path = sys.argv[2] In such a case how can we convert the path to UNICODE? Thank you once again, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: intermediate python csv reader/writer question from a beginner
Learning Python labm...@gmail.com wrote: anything related to csv, I usually use VB within excel to manipulate the data, nonetheless, i finally got the courage to take a dive into python. i have viewed a lot of googled csv tutorials, but none of them address everything i need. Nonetheless, I was wondering if someone can help me manipulate the sample csv (sample.csv) I have generated: ,, someinfo,,, somotherinfo,,, SEQ,Names,Test1,Test2,Date,Time,, 1,Adam,1,2,Monday,1:00 PM,, 2,Bob,3,4,Monday,1:00 PM,, 3,Charlie,5,6,Monday,1:00 PM,, 4,Adam,7,8,Monday,2:00 PM,, 5,Bob,9,10,Monday,2:00 PM,, 6,Charlie,11,12,Monday,2:00 PM,, 7,Adam,13,14,Tuesday,1:00 PM,, 8,Bob,15,16,Tuesday,1:00 PM,, 9,Charlie,17,18,Tuesday,1:00 PM,, into (newfile.csv): Adam-Test1,Adam-Test2,Bob-Test1,Bob-Test2,Charlie-Test1,Charlie- Test2,Date,Time 1,2,3,4,5,6,Monday,1:00 PM 7,8,9,10,11,12,Monday,2:00 PM 13,14,15,16,17,18,Tuesday,1:00 PM note: 1. the true header doesn't start line 4 (if this is the case would i have to use split?) 2. if there were SEQ#10-12, or 13-15, it would still be Adam, Bob, Charlie, but with different Test1/Test2/Date/Time I'm not really sure what you are trying to calculate, but this should give you some ideas... import csv from collections import defaultdict reader = csv.reader(open(sample.csv)) result = defaultdict(list) for row in reader: # ignore unless first row is numeric if not row or not row[0].isdigit(): continue n, name, a, b, day, time = row[:6] print n=%r, name=%r, a=%r, b=%r, day=%r, time=%r % (n, name, a, b, day, time) result[(day, time)].append(n) writer = csv.writer(open(newfile.csv, w)) for key, values in result.iteritems(): day, time = key values = values + [day, time] writer.writerow(values) This prints n='1', name='Adam', a='1', b='2', day='Monday', time='1:00 PM' n='2', name='Bob', a='3', b='4', day='Monday', time='1:00 PM' n='3', name='Charlie', a='5', b='6', day='Monday', time='1:00 PM' n='4', name='Adam', a='7', b='8', day='Monday', time='2:00 PM' n='5', name='Bob', a='9', b='10', day='Monday', time='2:00 PM' n='6', name='Charlie', a='11', b='12', day='Monday', time='2:00 PM' n='7', name='Adam', a='13', b='14', day='Tuesday', time='1:00 PM' n='8', name='Bob', a='15', b='16', day='Tuesday', time='1:00 PM' n='9', name='Charlie', a='17', b='18', day='Tuesday', time='1:00 PM' And leaves newfile.csv with the contents 1,2,3,Monday,1:00 PM 7,8,9,Tuesday,1:00 PM 4,5,6,Monday,2:00 PM -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Reference or Value?
En Tue, 24 Feb 2009 06:44:01 -0200, andrew cooke and...@acooke.org escribió: Steven D'Aprano wrote: On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: Steven D'Aprano wrote: On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: as far as i understand things, the best model is: 1 - everything is an object 2 - everything is passed by reference Except that is wrong. If it were true, you could do this: [pointer swapping] i was thinking of how the stack is used; i would have called what you are talking about pointer semantics. however, on reading around a little, it seems that i'm in a very small minority (which is a pity, because if you restrict the meaning to how values are handled on the stack then you get a lot closer to having just values and references, rather than the whole pile of different terms that are apparently in use). sorry for the confusion, Why is it a pity to have a whole pile of different terms to describe a whole lot of different behaviours? I would suggest the real confusion would be if we had two terms to describe a dozen different parameter- passing conventions. because: (1) it's often useful to explain things as (simpler) orthogonal components rather than globbing everything under one term; that lets you more easily carry across knowledge from previous experience. (2) while using a term that has (according to wikipedia) widespread usage in the Python community helps you save time and avoid confusion, it doesn't necessarily explain best to someone from outside that community what is happening. in this particular case you are getting dangerously close to having a term that is used only for one language and which, therefore, is at risk of meaning little more that the way python does it (which is, i think you'll agree, more tautological than helpful). But -paraphrasing A.E.- we should explain it in the simplest terms, but not simpler. Some people think that there exist only two possible ways to pass an argument: by value or by reference. The way Python does it doesn't have the same properties that pass-by-value nor pass-by-reference have in other languages, so both names are inapropiate. You appear to favor the by reference name. A couple months ago some other guy were strongly defending the by value name -- he even set up a website supporting his idea. The fact is, if you say it's by value you'll disappoint some expectations from some users, and if you say it's by reference you'll disappoint some other expectations. So you must say something different (it's by reference, but the references cannot be modified (!), and..., it's by value, but the values are references (!!), and..., or whatever description you choose). Given that, it's better to use a different name: you're going to explain the concept anyway. And Python isn't the first language using this convention; if you look in the FAQ or search recent threads in this group you'll find references going back to the '70s. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem in accessing files with unicode fonts.
En Tue, 24 Feb 2009 07:18:41 -0200, venutaurus...@gmail.com venutaurus...@gmail.com escribió: Thank you for your solution. It really helped. But how should I give if my path is in a varialble. For ex: path has that value obtained through command line arguments. path = sys.argv[2] In such a case how can we convert the path to UNICODE? If you know the encoding used for your file names, use it; else try sys.getfilesystemencoding() fsencoding = sys.getfilesystemencoding() path = sys.argv[2].decode(fsencoding) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Reference or Value?
Gabriel Genellina wrote: En Tue, 24 Feb 2009 06:44:01 -0200, andrew cooke and...@acooke.org escribió: Steven D'Aprano wrote: On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: Steven D'Aprano wrote: On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: as far as i understand things, the best model is: 1 - everything is an object 2 - everything is passed by reference Except that is wrong. If it were true, you could do this: [pointer swapping] i was thinking of how the stack is used; i would have called what you are talking about pointer semantics. however, on reading around a little, it seems that i'm in a very small minority (which is a pity, because if you restrict the meaning to how values are handled on the stack then you get a lot closer to having just values and references, rather than the whole pile of different terms that are apparently in use). sorry for the confusion, Why is it a pity to have a whole pile of different terms to describe a whole lot of different behaviours? I would suggest the real confusion would be if we had two terms to describe a dozen different parameter- passing conventions. because: (1) it's often useful to explain things as (simpler) orthogonal components rather than globbing everything under one term; that lets you more easily carry across knowledge from previous experience. (2) while using a term that has (according to wikipedia) widespread usage in the Python community helps you save time and avoid confusion, it doesn't necessarily explain best to someone from outside that community what is happening. in this particular case you are getting dangerously close to having a term that is used only for one language and which, therefore, is at risk of meaning little more that the way python does it (which is, i think you'll agree, more tautological than helpful). But -paraphrasing A.E.- we should explain it in the simplest terms, but not simpler. Some people think that there exist only two possible ways to pass an argument: by value or by reference. The way Python does it doesn't have the same properties that pass-by-value nor pass-by-reference have in other languages, so both names are inapropiate. You appear to favor the by reference name. A couple months ago some other guy were strongly defending the by value name -- he even set up a website supporting his idea. The fact is, if you say it's by value you'll disappoint some expectations from some users, and if you say it's by reference you'll disappoint some other expectations. So you must say something different (it's by reference, but the references cannot be modified (!), and..., it's by value, but the values are references (!!), and..., or whatever description you choose). Given that, it's better to use a different name: you're going to explain the concept anyway. if you read my post i think you'll find i was not advocating either of those. i really think this discussion has gone on far enough; i have better things to do. andrew And Python isn't the first language using this convention; if you look in the FAQ or search recent threads in this group you'll find references going back to the '70s. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: A tale of two execs
On Feb 23, 9:13 pm, aha aquil.abdul...@gmail.com wrote: Hello All, It occurred to me that I might just want to try copying the subprocess.py installed in a /usr/lib/python24 installation to the directory where I place the scripts that I need to launch my application...I know this was mentioned earlier. Anyway, my application worked under python 2.3 and later python versions as well. Here is what I did: I renamed subprocess.py to subprocess23.py and then used the following code: try: import subprocess except ImportError: import subprocess23 as subprocess I chose this route because I took a deeper look at the code in the subprocess module and I also realized that I would not be able to use the popen2, because I would not be able to do things like os.setpgrp for preexec_fn, with popen2. In the end, if I wanted that type of functionality I would have to use os.dup, fork, exec, which meant reinventing the wheel. I overcame the issue of dealing with msvcrt and _subprocess under windows by requiring python24 or greater under windows. Distributing the interpreter doesn't look quite as silly as it did this morning now, does it? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter icons as bytestrings, not files?
En Tue, 24 Feb 2009 02:56:12 -0200, Peter Billam pe...@www.pjb.com.au escribió: As a newbie, starting with Python3, I'm working my way through Mark Summerfield's tkinter examples. In the toolbar, there's lines like: image = os.path.join(os.path.dirname(__file__), image) image = tkinter.PhotoImage(file=image) which are always failing because the icons are in the wrong place and I can't help but wonder if I can put all these little images in the application itself, either as b'whatever' or uuencoded or in svg etc, and then invoke some suitable variation of the image = tkinter.PhotoImage(file=image) or of the button = tkinter.Button(toolbar, image=image, command=command) command ? (I did try help('tkinter.PhotoImage') but didn't spot a magic key (unless it's data=something, format=something)) ... Almost; see the best documentation source for tkinter: http://effbot.org/tkinterbook/photoimage.htm -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Python, HTTPS (SSL), tlslite and POST method (and lots of pain)
OK I found workaround. So just for other fighting the same thing: Instead of using tlslite use pyOpenSSL and as a base for your server you can use: http://code.activestate.com/recipes/442473/ When you add do_POST method everything works greetz Jacek -- http://mail.python.org/mailman/listinfo/python-list
Re: Reference or Value?
andrew cooke wrote: Steven D'Aprano wrote: On Mon, 23 Feb 2009 08:14:34 -0300, andrew cooke wrote: Steven D'Aprano wrote: On Sun, 22 Feb 2009 13:37:27 -0300, andrew cooke wrote: as far as i understand things, the best model is: 1 - everything is an object 2 - everything is passed by reference Except that is wrong. If it were true, you could do this: [pointer swapping] i was thinking of how the stack is used; i would have called what you are talking about pointer semantics. however, on reading around a little, it seems that i'm in a very small minority (which is a pity, because if you restrict the meaning to how values are handled on the stack then you get a lot closer to having just values and references, rather than the whole pile of different terms that are apparently in use). sorry for the confusion, Why is it a pity to have a whole pile of different terms to describe a whole lot of different behaviours? I would suggest the real confusion would be if we had two terms to describe a dozen different parameter- passing conventions. because: (1) it's often useful to explain things as (simpler) orthogonal components rather than globbing everything under one term; One term? If you look at this Wikipedia page: http://en.wikipedia.org/wiki/Evaluation_strategy you should be able to count no fewer than thirteen different terms for different evaluation strategies, and call-by-value itself is described as a family of strategies. Who is gobbing everything under one term? Certainly not me. If anything, your preferred tactic is to gob everything under one of two terms, call-by-value and call-by-reference. That's not my preferred tactic. that lets you more easily carry across knowledge from previous experience. That's only useful if that previous experience *clarifies* rather than *confuses*. This very thread demonstrates that people's prior knowledge of call-by-whatever doesn't clarify Python's behaviour. (2) while using a term that has (according to wikipedia) widespread usage in the Python community helps you save time and avoid confusion, it doesn't necessarily explain best to someone from outside that community what is happening. And you think call-by-reference does? Python demonstrably does not behave like call-by-reference in other languages. I do not agree that it is wise to hammer the round peg of Python's actual behaviour into the square peg of newbies' concept of call-by-reference. in this particular case you are getting dangerously close to having a term that is used only for one language So what? What if Python was the only language that used the term? That doesn't make it inappropriate. If the users of other languages that use call-by-object semantics (Java, RealBasic, etc) choose to prefer a misleading name over a descriptive name, that's no reason for Python users to follow down their path. and which, therefore, is at risk of meaning little more that the way python does it (which is, i think you'll agree, more tautological than helpful). No at all. Do you imagine that call-by-name means the way Algol does it? Algol is the only major language that uses call-by-name, it may even be the only language of any size, but that doesn't mean that call-by-name can't be defined and described independently of Algol. There's even a test, Knuth's Man Or Boy Test, for testing how well a language implements call-by-name semantics. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
undefined reference to `init_warnings' when compiling after freeze...
Hello Python users I am trying to compile .py files using freeze with Python 2.6.1, but I get an error even when trying with hello.py from the examples. Freeze semes to do its work (last lines only): p...@linux-s7f4:~/soft/Python-2.6.1/Tools/freeze python freeze.py hello.py generating table of frozen modules Warning: unknown modules remain: _bisect _collections _ctypes _functools _heapq _locale _random _socket _ssl _struct array binascii cPickle cStringIO fcntl itertools math operator readline select strop termios time Now run make to build the target: hello Now comes make: p...@linux-s7f4:~/soft/Python-2.6.1/Tools/freeze make gcc -pthread -Xlinker -export-dynamic config.o frozen.o M_BaseHTTPServer.o M_FixTk.o M_SocketServer.o M_StringIO.o M_Tkconstants.o M_Tkinter.o M_UserDict.o M___future__.o M___main__.o M__abcoll.o M__threading_local.o M_abc.o M_base64.o M_bdb.o M_bisect.o M_cmd.o M_codecs.o M_collections.o M_copy.o M_copy_reg.o M_ctypes.oM_ctypes___endian.o M_ctypes__macholib.o M_ctypes__macholib__dyld.o M_ctypes__macholib__dylib.o M_ctypes__macholib__framework.o M_ctypes__util.o M_difflib.o M_dis.o M_distutils.o M_distutils__dep_util.o M_distutils__errors.o M_distutils__log.o M_distutils__spawn.o M_distutils__sysconfig.o M_distutils__text_file.o M_distutils__util.o M_doctest.o M_dummy_thread.o M_dummy_threading.o M_email.o M_email___parseaddr.o M_email__base64mime.o M_email__charset.o M_email__encoders.o M_email__errors.o M_email__feedparser.o M_email__message.o M_email__mime.o M_email__parser.o M_email__quoprimime.o M_email__utils.o M_encodings.o M_encodings__aliases.o M_fnmatch.o M_formatter.o M_ftplib.o M_functools.o M_genericpath.o M_getopt.o M_getpass.o M_gettext.o M_glob.o M_heapq.o M_httplib.o M_inspect.o M_keyword.o M_linecache.o M_locale.o M_macurl2path.o M_mimetools.o M_mimetypes.o M_ntpath.o M_nturl2path.o M_opcode.o M_optparse.o M_os.o M_os2emxpath.o M_pdb.o M_pickle.o M_pkgutil.o M_posixpath.o M_pprint.o M_py_compile.o M_pydoc.o M_pydoc_topics.o M_quopri.o M_random.o M_re.o M_repr.oM_rfc822.o M_shlex.o M_site.o M_socket.o M_sre_compile.o M_sre_constants.o M_sre_parse.o M_ssl.o M_stat.o M_string.o M_struct.o M_subprocess.o M_tempfile.o M_textwrap.o M_threading.o M_token.o M_tokenize.o M_traceback.o M_tty.o M_types.o M_unittest.o M_urllib.o M_urlparse.o M_uu.o M_warnings.o M_webbrowser.o /home/ps/app/lib/ python2.6/config/libpython2.6.a -lpthread -ldl -lutil -lm -o hello /home/ps/app/lib/python2.6/config/libpython2.6.a(posixmodule.o): In function `posix_tmpnam': /home/ps/soft/Python-2.6.1/./Modules/posixmodule.c:7079: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp' /home/ps/app/lib/python2.6/config/libpython2.6.a(posixmodule.o): In function `posix_tempnam': /home/ps/soft/Python-2.6.1/./Modules/posixmodule.c:7034: warning: the use of `tempnam' is dangerous, betteruse `mkstemp' config.o:(.data+0x28): undefined reference to `init_warnings' collect2: ld returned 1 exit status make: *** [hello] Error 1 I tested it on OpenSuSe 11.0 and Ubuntu 8.10 with the same results. Did somebody experienced the same problem? With Python 2.5.1 it works without problems. Thanks in advance Pablo -- http://mail.python.org/mailman/listinfo/python-list
try except question - serious foo bar question, and pulling my hair out :-)
Given this class below: import Queue import threading from sorb.util.dumpexc import dumpexc import waitablemixin PREFETCH_SIZE = 10 class Feeder(threading.Thread,waitablemixin.WaitableMixin): def __init__(self,connection_manager): self.cm = connection_manager self.expired_asins = Queue.Queue() self.logger = self.cm.loggerfactory.get_logger(feeder) threading.Thread.__init__(self) def run(self): try: try: d = self.cm.create_dispatcher() try: od_producer = d.locate('od_producer') while not self.cm.stop_requested.isSet(): try: items = od_producer.getsomeasins() if items: self.logger.info(Got %d items to process,len(items)) for item in items: self.expired_asins.put(item) if self.expired_asins.qsize()PREFETCH_SIZE: while (self.expired_asins.qsize()PREFETCH_SIZE) and \ not self.cm.stop_requested.isSet(): self.logger.info( %s (%s) items in the queue, waiting..., self.expired_asins.qsize(), PREFETCH_SIZE ) self.waitsome(1) else: self.logger.info(No more items to process, will wait 5 minutes.) self.waitsome(5*60) except Exception,e: self.logger.error(Could not get asins: %s,dumpexc(e) ) self.logger.error(Will retry in 10 seconds.) self.waitsome(10) finally: d.close() except Exception,e: self.cm.stop_requested.set() self.logger.error(dumpexc(e)) finally: self.logger.error(Feeder stopped. stop_requested = %s,str(self.cm.stop_requested.isSet())) How in the hell can I get the following log output: 2009-02-24 11:42:14,696 INFO .feeder Got 5 items to process 2009-02-24 11:42:14,732 INFO .feeder Got 5 items to process 2009-02-24 11:42:14,733 INFO .feeder 15 (10) items in the queue, waiting... 2009-02-24 11:42:15,740 INFO .feeder 15 (10) items in the queue, waiting... 2009-02-24 11:42:16,965 ERROR .feeder Feeder stopped. stop_requested = False It seems impossible to me. The while loop should only exit if stop_requested becomes set, OR if an exception is raised. However, all exceptions are cought and logged. But there are no exceptions logged. And stop_requested is NOT SET. (see the last line in the log). What is happening here? -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
En Tue, 24 Feb 2009 09:22:41 -0200, Laszlo Nagy gand...@shopzeus.com escribió: Given this class below: [code removed] It seems impossible to me. The while loop should only exit if stop_requested becomes set, OR if an exception is raised. However, all exceptions are cought and logged. But there are no exceptions logged. And stop_requested is NOT SET. (see the last line in the log). I assume stop_requested is an Event object. Maybe other thread cleared it? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
I assume stop_requested is an Event object. Maybe other thread cleared it? It was never set! - nothing can clear it. -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
I assume stop_requested is an Event object. Maybe other thread cleared it? It was never set! - nothing can clear it. In theory, it could be that a thread sets the event object. E.g.: #1. other thread calls stop_requested.set() #2. while not self.stop_requested.isSet() -- loop exists #3. other thread calls stop_requested.clear() #4. called this: self.logger.error(Feeder stopped. stop_requested = %s,str(self.cm.stop_requested.isSet())) However, this cannot happen. This application is running multiple threads (10+) and every thread monitors the global stop_requested flag. If there was an unexpected error in the service, stop_requested.set() is called. It will stop all threads and exit the process. stop_requested.clear() is NEVER called, so the while loop should have not been ended. So what is happening here? It drives me crazy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte type?
2009/2/24 John Nagle na...@animats.com: Martin v. Löwis wrote: Please don't call something dumb that you don't fully understand. It's offenses the people who have spent lots of time developing Python -- personal, unpaid and voluntary time! Some of the people involved are on Google's payroll. Uh, what does that have to do with anything? It would only be relevant if you are saying that Google is paying them to do the work (so not just on their payroll). More importantly, it's also only relevant if ALL the people contributing are being paid by Google to do the work, which I'm pretty sure is not the case. There are people are spending lots of personal, unpaid and voluntary time developing Python. Paddy -- Ray, when someone asks you if you're a god, you say YES! -- http://mail.python.org/mailman/listinfo/python-list
Re: Newby - is this what they are looking for ?? and is their a better a way
On Tue, Feb 24, 2009 at 4:54 AM, Gary Wood woody...@sky.com wrote: ''' program. 1.What type of data will the input be? What type of data will the output be? 2.Get the phrase from the user. 3.Convert to upper case. 4.Divide the phrase into words. 5.Initialize a new empty list, letters. 6.Get the first letter of each word. 7.Append the first letter to the list letters. 8.Join the letters together, with no space between them. 9.Print the acronym. You're not doing 5 or 7-9 right. Where's the `letters` list they asked for? Which of these steps is in a loop? What for statement controls this loop? ''' line = input('enter a phrase') lines = line.upper() seq = lines.split() for i in seq: word = (i[0]) print(word, end='') Hint: `print` shouldn't be used inside the loop at all. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
It seems impossible to me. The while loop should only exit if stop_requested becomes set, OR if an exception is raised. However, all exceptions are cought and logged. But there are no exceptions logged. And stop_requested is NOT SET. (see the last line in the log). What is happening here? It was a bad assumption. Not all exceptions are subclasses of Exception. In this case, an inner call raised SystemExit(0). So be aware. Don't think that this will catch all exceptions: try: ??? except Exception,e: do_with(e) Use this instead: import sys try: ??? except: e = sys.exc_value do_with(e) Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: How to read columns in python
Dhananjay wrote: Well, The three columns are tab separated and there are 200 such rows having these 3 columns in the file. First two columns are x and y coordinates and third column is the corresponding value. I want to read this file as a matrix in which column1 correspond to row, column2 corresponds to columns(in matrix) and column3 corresponds to value in the matrix. -- Dhananjay On Tue, Feb 24, 2009 at 12:18 PM, Chris Rebert c...@rebertia.com mailto:c...@rebertia.com wrote: On Mon, Feb 23, 2009 at 10:41 PM, Dhananjay dhananjay.c.jo...@gmail.com mailto:dhananjay.c.jo...@gmail.com wrote: I am bit new to python and programming and this might be a basic question: I have a file containing 3 columns. Your question is much too vague to answer. What defines a column for you? Tab-separated, comma-separated, or something else altogether? Try something like f = open(datafile.txt, 'r') x = []; y = []; val = [] for line in f: xx, yy, vv = line.split() x.append(float(xx)) y.append(float(yy)) val.append(float(vv)) Of course this is only one way to represent the data - as vectors of x, y and val. If you just wanted a list of the data triples then you could have written f = open(datafile.txt, 'r') values = [] for line in f: x, y, v = line.split() values.append(float(x), float(y), float(v)) regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Newby - is this what they are looking for ?? and is their a better a way
''' program. 1.What type of data will the input be? What type of data will the output be? 2.Get the phrase from the user. 3.Convert to upper case. 4.Divide the phrase into words. 5.Initialize a new empty list, letters. 6.Get the first letter of each word. 7.Append the first letter to the list letters. 8.Join the letters together, with no space between them. 9.Print the acronym. Which of these steps is in a loop? What for statement controls this loop? ''' line = input('enter a phrase') lines = line.upper() seq = lines.split() for i in seq: word = (i[0]) print(word, end='') -- http://mail.python.org/mailman/listinfo/python-list
Re: Python C-API Object Allocation
On Feb 21, 2009, at 10:01 AM, William Newbery wrote: Ive been learning the C-API lately so I can write python extensions for some of my c++ stuff. First thing that comes to (my) mind is that you probably do not want to write code against the bare C-API. Instead, give Cython a try. http://cython.org Stefan -- http://mail.python.org/mailman/listinfo/python-list
Extract CDATA Node
How do I extract CDATA node in Python? I'm using dom.minidom as follows:- from xml.dom.minidom import Document class XMLDocument(): def __init__(self): self.doc = Document() def parseString(self, d): self.doc = parseString(_encode(d)) return self #Create instance of XMLDocument doc = XMLDocument() doc.parseString(open(os.curdir + '\\XML\\1.xml', 'r').read()) . Please help me out. Thanks, Girish -- http://mail.python.org/mailman/listinfo/python-list
Re: Extract CDATA Node
On Tue, 24 Feb 2009 05:29:21 -0800 (PST), Girish girish@gmail.com wrote: How do I extract CDATA node in Python? I'm using dom.minidom as follows:- from xml.dom.minidom import Document class XMLDocument(): def __init__(self): self.doc = Document() def parseString(self, d): self.doc = parseString(_encode(d)) return self #Create instance of XMLDocument doc = XMLDocument() doc.parseString(open(os.curdir + '\\XML\\1.xml', 'r').read()) . Please help me out. Here's one approach. from xml.dom.minidom import parse doc = parse(file('XML/1.xml')) cdata = [] elements = [doc.documentElement] while elements: e = elements.pop(0) if e.nodeType == doc.TEXT_NODE: cdata.append(e.data) elif e.nodeType == doc.ELEMENT_NODE: elements[:0] = e.childNodes print cdata I bet there are simpler ways, though, based on other XML libraries. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: more on unescaping escapes
On Tue, 24 Feb 2009 00:46:34 -, bvdp b...@mellowood.ca wrote: Just because I never really thought too much about it :) I'm doing my work on a linux box and my user is on windows ... and he's used to using '\' ... but, you are absolutely right! Just use '/' on both systems and be done with it. Of course I still need to use \x20 for spaces, but that is easy. Erm, no. \x20 is exactly the same as in a string literal. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Which group ...
Ok, thanks ... I am going to be asking a lot of questions now ;- -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
Laszlo Nagy wrote: I assume stop_requested is an Event object. Maybe other thread cleared it? It was never set! - nothing can clear it. In theory, it could be that a thread sets the event object. E.g.: #1. other thread calls stop_requested.set() #2. while not self.stop_requested.isSet() -- loop exists #3. other thread calls stop_requested.clear() #4. called this: self.logger.error(Feeder stopped. stop_requested = %s,str(self.cm.stop_requested.isSet())) However, this cannot happen. This application is running multiple threads (10+) and every thread monitors the global stop_requested flag. If there was an unexpected error in the service, stop_requested.set() is called. It will stop all threads and exit the process. stop_requested.clear() is NEVER called, so the while loop should have not been ended. So what is happening here? It drives me crazy. Time to get a stuffed toy and go through your code, explaining to the toy exactly why your code is right and nothing can go wrong. With luck, within half an hour you will realize what you are doing wrong ... regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Reference or Value?
2009/2/24 Steven D'Aprano st...@pearwood.info: If you look at this Wikipedia page: http://en.wikipedia.org/wiki/Evaluation_strategy you should be able to count no fewer than thirteen different terms for different evaluation strategies, and call-by-value itself is described as a family of strategies. And that call by sharing is a member of that family even though the behaviour is (as I understand it) exactly what you would get if you pass an object by ^reference^ in C++. Wikipedia can be a double-edged sword ;-). I think the problem is that Call by value and Call by reference are terms that pre-date object orientation, and don't cope well with obect-oriented languages in general, not just with Python. That Java programmers get by thinking the mechanism is called call by value, C++ programmers get by thinking the same mechanism is called call by reference and Python programmers get by thinking the same mechanism is called call by sharing suggests that the terms are no longer helpful. Programmers in one language simply can't know what the terminology means when applied to another language without learning the behaviour in that other language before learning the terminology. That means that Torsten's original question probably wasn't the one he wanted to ask, and wasn't a useful one. The useful question is what is Python's parameter passing *behaviour^, with a possible supplementary what do they call that behaviour *in the Python community*, recognising that if they asked what is Java's parameter passing *behaviour^, with the supplementary what do they call that behaviour *in the Java community* they would get much the same answer for the first question (immutability is handled differently, I think, but it's there) but a totally different answer to the second. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending Python Questions .....
On Feb 23, 2:31 pm, Nick Craig-Wood n...@craig-wood.com wrote: Ben bnsili...@gmail.com wrote: In My S-Lag Project called, SLAG, I have some function keys that get mapped back to S-lang internal functions. My SLAG project works pretty much like Python (as does the S-Lang). You write a S-lang script that imports your extension. module - and all this gets run by the shell/interpreter. I allow function keys to be mapped back internal function(s) inside of the controlling program. My question is which Python C api Do I need to this with ? Do you mean like this? http://code.google.com/p/python-slang Not sure how well maintained it is though. Do I need to worry about my reference counting since the Python Program is in essence calling a function in itself? I'm not sure I understand you here, but in general you don't need to worry about reference counting in Python - it all happens behind the scenes. If you are writing a python extension in C then you do need to worry about reference counting - a lot! -- Nick Craig-Wood n...@craig-wood.com --http://www.craig-wood.com/nick No, It uses the the S-lang for video, and input control. However, SLAG is more of an abstract layer on top of that. It has a Structures that contains menus and screens (menumodule / screenmodule). One LOADS them up with parameters. such as creating a new menu is like: OpenMenu( Company name, SubSystem, this program name, mode, bottom status display) - Create initial menu structure Addtomenu(Menu Block Set name, DISPLAY line, ID, type of program, password ID ) - add to / update MENU blocks. runMenu() - Displays the whole create menu structure. The Menu structure is done in pull downs and scrollable blocks in a TUI (text User Interface) and using the S-lang screen library is fully mouseable. The screen module works mych the same way, but with the abiltity to open and close and work within Sub Screens. For those who do not know, S-lang is a interpreted language much like Python. However, there is s direth of library modules. The original S-lang started out as library of screen of keyboard modules, but has been expanded My SLAG project does not care in reality WHICH or what language, it is simply handling menu and screen control. Hope this helps ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Running script in module initialization
En Mon, 23 Feb 2009 05:51:27 -0200, Kom2 k...@centrum.cz escribió: On 20 Ún, 16:27, Steve Holden st...@holdenweb.com wrote: Kom2 wrote: Hello, I'm trying to convert my project from python 2.5 to python 3.0 and I have the following problem. My project is PYD library written in C++. So I have this PyInit_ModuleName function containing PyModule_Create call and this function also call some script with declarations: PyObject* m; m = PyModule_Create(PyVRDAModule); if (m == NULL) { return NULL; } PyObject *d, *v; d = PyModule_GetDict(m); v = PyRun_StringFlags(txtPyPredefinedConstants), Py_file_input, d, d, NULL); .. txtPyPredefinedConstants is string with this content: class CursorMoveType: First = 0 Last = 1 Next = 2 Previous = 3 Bookmark = 4 NewRecord = 5 In Python 2.5 everything works fine, now in python3.0 PyRun_StringFlags returns NULL and I get error __build_class__ not found. __build_class__ is a (hidden?) function in the builtins module. Your module isn't completely created yet, it lacks the __builtins__ attribute, so you can't execute any Python code that calls a builtin function. In 2.5 the class statement was a lot simpler, but in 3.0 it requires an auxiliary function (implemented as builtins.__build_class__) You may try setting __builtins__ to the current builtins (PyEval_GetBuiltins) before executing Python code. Or, if those 7 lines are all you need, you may just write the equivalent C code. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
variables bound in moudules are None when module is not completely imported
when a module being loaded is interrupted by an exception, code blocks that have the module's scope in their environment will later evaluate variables bound to that module to None, instead of preserving that scope (because it is still referenced somewhere) or raising a NameError (for which i see no reason, but which would still be better than silently returning None). this can happen, for example, when one tries to join different programs in one main loop by having the modules first hook up to events and then terminating the subprograms by replacing the call to the main loop with an exception raiser. attached, there is a tarball with two similar examples, one demonstrating that with functions instead of modules (this behaves as expected; ./function/), the other showing that when a module's block is terminated, the remaining variables are set to None (./module/); both can be run by calling `python main.py` in the respective directory. * is this a bug in the pythin implementation? (i've tested it both with 2.5 and with 3.0b2) * if yes, is it identical to [1748015]? (i suppose it is, but lacking experience with pdb i am not sure) * can / will this be fixed? * is there a workaround? * especially, is there a workaround that works w/o rewriting the modules that raise the exceptions? (otherwise, wrapping all the stuff called in the __name__==__main__ wrapper into a main() function and then calling that would trivially solve that) answers to any of these questions would be very much appreciated regards chrysn [1748015] http://bugs.python.org/issue1748015 -- To use raw power is to make yourself infinitely vulnerable to greater powers. -- Bene Gesserit axiom module_none.tar.bz2 Description: Binary data signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
En Tue, 24 Feb 2009 11:09:44 -0200, Laszlo Nagy gand...@shopzeus.com escribió: It seems impossible to me. The while loop should only exit if stop_requested becomes set, OR if an exception is raised. However, all exceptions are cought and logged. But there are no exceptions logged. And stop_requested is NOT SET. (see the last line in the log). What is happening here? It was a bad assumption. Not all exceptions are subclasses of Exception. In this case, an inner call raised SystemExit(0). Glad to see you finally found what was happening! So be aware. Don't think that this will catch all exceptions: try: ??? except Exception,e: do_with(e) Use this instead: import sys try: ??? except: e = sys.exc_value do_with(e) Only at the outermost block on your code, if ever... The fact that some exceptions don't inherit from Exception is on purpose -- usually you *dont* want to catch (and swallow) SystemExit (nor KeyboardInterrupt, and a few more I think) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: shared lib from python code?
andrew cooke wrote: Gabriel Rossetti wrote: Ok, maybe I mis-stated my problem (or mis-understood your answers).. I don' t want to share code as in have multiple processes access a variable and have the same value, like it is done in threads, what I want is to not have n copies of the code (classes, functions, etc) loaded by n python interpreters. When you load Apache for instance, it runs n processes but loads only one copy of parts of it's code (so/dll), that's what I want to do. In C/C++ I would write a shared-lib (so/dll), so once the system has loaded it, it doesn' t re-load it when another process needs it. i think i understand what you want. the problem is that the kind of language that python is really doesn't work well with that kind of approach. this is (and i may be wrong - i've not really thought much about this before) largely because python places a very strong emphasis on late binding. that means that everything is very flexible - all kinds of things can be changed under the hood. and that means that it is very difficult to share things safely because almost any solution would end up doing what you don't want (sharing variables, like with threads (even though they are very deeply buried variables)) rather than what you do want (just sharing the static part of the code to save space). another way to see this is to see the connection with security. this is the flip side of your case - because things are so flexible it is very hard to run some python code in a sandbox in a larger python program. there's some discussion on the dev group at the moment and it looks like the solution is to only use function closures. but even that doesn't work without some patches that remove certain ways to dynamically alter the code base. andrew Ok, I see, thank you. I thought this was possible since I have used *.pyd files before and from what I had read they were dynamic library files. I guess they must be written in C/C++ then. Thank you for the explanation. Gabriel -- http://mail.python.org/mailman/listinfo/python-list
Re: shared lib from python code?
Duncan Booth wrote: Gabriel Rossetti gabriel.rosse...@arimaz.com wrote: Ok, maybe I mis-stated my problem (or mis-understood your answers).. I don' t want to share code as in have multiple processes access a variable and have the same value, like it is done in threads, what I want is to not have n copies of the code (classes, functions, etc) loaded by n python interpreters. When you load Apache for instance, it runs n processes but loads only one copy of parts of it's code (so/dll), that's what I want to do. In C/C++ I would write a shared-lib (so/dll), so once the system has loaded it, it doesn' t re-load it when another process needs it. It doesn't matter how you restate it, the answer is still the one Gabriel Genellina gave you: Python code objects are not shared between processes. Ok, I had though that he had misunderstood me. Code objects are immutable, but they are still objects like everything else in Python. That means they are reference counted and discarded when no longer referenced. To share code objects between different processes you would have to change the reference counting mechanism so it was either safe across multiple processes or didn't reference count shared code objects (but still ref counted non-shared objects). The actual code is just stored in a string, so perhaps you could share those strings between processes: just executing the code doesn't change the string's refcount (whereas it does change the function and the code objects' counts). You could probably make something work simply by editing the code constructor to move the code into shared memory and using some other mechanism to control the shared memory storage. Ok, thanks for the explanation. C extension libraries on the other hand may be shared. Ok, so pyd files must be C extensions then. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: reading file to list
On 17 Jan, 17:16, Xah Lee xah...@gmail.com wrote: comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby Here's a interesting toy problem posted by Drew Krause to comp.lang.lisp: On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]: OK, I want to create a nested list in Lisp (always of only integers) from a text file, such that each line in the text file would be represented as a sublist in the 'imported' list. example of a file's content 3 10 2 4 1 11 18 example of programing behavior (make-list-from-text blob.txt) = ((3 10 2) (4 1) (11 18)) - Here's a emacs lisp version: (defun read-lines (file) Return a list of lines in FILE. (with-temp-buffer (insert-file-contents file) (split-string (buffer-substring-no-properties 1 (point-max)) \n t) ) ) (defvar mylist '() result list ) (setq mylist '()) ; init in case eval'd again (mapc (lambda (x) (setq mylist (cons (split-string x ) mylist )) ) (read-lines xxblob.txt) ) The above coding style is a typical maintainable elisp. In a show-off context, it can be reduced to by about 50%, but still far verbose than ruby or say perl (which is 1 or 2 lines. (python would be 3 or 5)). Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that. The “read-lines” function really should be a built-in part of elisp. It is not so mostly because emacs people have drawn themselves into a elitist corner, closing off to the outside world. (i am sending a suggestion to the official emacs dev list on adding read-line now.) scheme: (define (read-line port) (define (rec-read-line port line) (define next-char (peek-char port)) (define number #f) (cond ((eof-object? next-char) '()) ((char=? next-char #\newline) (read-char port) line) ((char-numeric? next-char) (set! number (read port)) (cons number (rec-read-line port line))) ((char=? next-char #\space) (read-char port) (rec-read-line port line)) (else (error (string-append bad character \ (string next-char) \))) )) (rec-read-line port '()) ) (define (make-int-list port) (define line (read-line port)) (if (null? line) '() (cons line (make-int-list port (define (make-list-from-text file) (make-int-list (open-input-file file))) - w_a_x_...@yahoo.com gave a ruby solution: IO.readlines(blob.txt).map{|line| line.split } augumented by Jilliam James for result to be numbers: IO.readlines(blob.txt).map{|line| line.split.map{|s| s.to_i }} Very beautiful. --- That's really the beauty of Ruby. This problem and ruby code illustrates 2 fundamental problems of lisp, namely, the cons problem, and the nested syntax pain. Both of which are practically unfixable. The lisp's cons fundamentally makes nested list a pain to work with. Lisp's nested syntax makes functional sequencing cumbersome. In the ruby code, its post-fix sequential notation (as a side effect of its OOP notation) brings out the beauty of functional sequencing paradigm (sometimes known as functional chain, sequencing, filtering, unix piping). its list, like all modern high level langs such as perl, php, python, javascript, don't have the lisp's cons problem. The cons destroys the usability of lists up-front, untill you have some at least 2 full-time years of coding lisp to utilize cons properly. (and even after that, it is still a pain to work with, and all you gain is a bit of speed optimization in rare cases that requires largish data, most of which has better solutions such as a database.) Both of these problems i've published articles on. For more detail on the cons problem, see the section “The Cons Business” at • Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html For more detail on the nested syntax problem for function chaining, see the section “How Purely Nested Notation Limits The Language's Utility” at: • The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Newby - is this what they are looking for ?? and is their a better a way
You're doing well so far. As Chris has said, you need to read the later part of the question more carefully. A couple of other things: 1. 'input' might not be the best way to get the phrase, because the user will have to put the phrase in quotes or the program will (probably) crash. Have a look at raw_input. 2. A cosmetic thing. Your users will be happier if you put a space after 'enter a phrase' 3. A better way might not be a better way for you. There's a very Pythonic way of doing this using something called list comprehensions, but they're almost certainly not what your tutor wants because they're rather more advanced than the level you're working at. If it wasn't for the requirement to put the acronym into the variable letters, the whole task could be done in one Python statement. Don't try that. Keep it simple, the way you have been so far. 4. If you want to be a wise guy, ask your tutor why he/she got you to convert the whole phrase to upper case, wasting a whole pile of character conversion operations under the hood, because it's only the acronym that needs to be converted :-) -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Unix Change Passwd Python CGI
I am using python version 2.5.1 and need to create a python cgi application to allow a user to change their unix password. Apache is running on the same system that needs the password changed. I need to keep security high and can not install additional modules at this time. I just need a general direction to start looking, and I do not have expect installed on the system. Any ideas would be wonderful! R/S -- - Derek Tracy trac...@gmail.com - -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
On 2009-02-24, Steve Holden st...@holdenweb.com wrote: However, this cannot happen. This application is running multiple threads (10+) and every thread monitors the global stop_requested flag. If there was an unexpected error in the service, stop_requested.set() is called. It will stop all threads and exit the process. stop_requested.clear() is NEVER called, so the while loop should have not been ended. So what is happening here? It drives me crazy. Time to get a stuffed toy and go through your code, explaining to the toy exactly why your code is right and nothing can go wrong. With luck, within half an hour you will realize what you are doing wrong ... It works with a person as well as stuffed toys -- but trying to order a person on the internet gets you in a lot more trouble. It's also a little more embarassing when you realize your mistake in front of a person. OTOH, sometimes a person will ask an enlightening question; but, sometimes they just make unhelpfull wisecracks. It's a tough choice. -- Grant Edwards grante Yow! OVER the underpass! at UNDER the overpass! visi.comAround the FUTURE and BEYOND REPAIR!! -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
Use this instead: import sys try: ??? except: e = sys.exc_value do_with(e) Only at the outermost block on your code, if ever... The fact that some exceptions don't inherit from Exception is on purpose -- usually you *dont* want to catch (and swallow) SystemExit (nor KeyboardInterrupt, and a few more I think) Yes, this was at the outermost block of my thread's run method. SystemExit exception did not generate an exception in Thread-32 type traceback on stderr because for Python, it seemed to be a normal exit of the thread. So I wrote an except block, to see why the thread has been stopping. In this case, catching SystemExit was desired. The problem was in my mind: I thought that except Exception,e: will catch everything. The solution was to replace raise SystemExit(0) with raise TransportClosedException() in another class. Thanks again, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Newby - is this what they are looking for ?? and is their a better a way
Tim Rowe wrote: 1. 'input' might not be the best way to get the phrase, because the user will have to put the phrase in quotes or the program will (probably) crash. Have a look at raw_input. Gary is using Python 3 where input() works like the raw_input() of yore. The giveaway is print(word, end='') Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python AppStore / Marketplace
Rhodri James rho...@wildebst.demon.co.uk wrote in message news:mailman.615.1235436896.11746.python-l...@python.org... A souq is a bazaar :-) Maybe I've just read too much arabic-themed fiction, but I was surprised not to find the word in my trusty Chambers. Try under 'souk'. Transliterating to the Roman 'q' seems to have become popular relatively recently. -- http://mail.python.org/mailman/listinfo/python-list
March 2, 2009 Pyowa Meeting
Hi, Just a quick note to say that our next Pyowa (Python Users Group of Iowa) meeting will be next Monday, March 2nd from 7-9 p.m. We will be in our original location at the Marshall County Sheriff's Office, 2369 Jessup Ave, Marshalltown, IA. Remember, it's technically NOT in Marshalltown at all. It's actually about 7 miles to the West of Marshalltown. Keep an eye on our website (www.pyowa.org) for updates and/or cancellations should the weather turn bad. We are currently going to have a presentation featuring real-life programs/scripts to give our members an idea of what Python is used for on a day-to-day basis. We'll probably open it up to the audience to see if they have anything to add. We are also hoping to have a presentation on some basic GIS scripts, but this is rather tentative. Regardless, there will be free drinks provided (pop / water). Let me know if you can make it! Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: thanks very much indeed for your help is there a better way to do this (python3) newby
On Feb 24, 6:29 am, Rhodri James rho...@wildebst.demon.co.uk wrote: On Mon, 23 Feb 2009 23:33:31 -, Gary Wood woody...@sky.com wrote: '''exercise to complete and test this function''' import string def joinStrings(items): '''Join all the strings in stringList into one string, and return the result. For example: print joinStrings(['very', 'hot', 'day']) 'veryhotday' ''' for i in items: return (''.join(items)) As I'm sure your teacher will point out, this is sub-optimal :-) That for-loop isn't doing anything, because you always return out of it at the first iteration. I suspect that you're expected to concatenate the strings together by hand and return the resulting string once you've done them all. Trying writing it that way. PS: it helps a lot if what you say in the doc string matches what you write in the rest of the code. In this case you call your input string items, but then say Join all the strings in *stringList*... -- Rhodri James *-* Wildebeeste Herder to the Masses Here is another way of doing this: print ('very' + 'hot' + 'day') Hope this helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter icons as bytestrings, not files?
On Tue, 24 Feb 2009 05:56:12 +0100, Peter Billam pe...@www.pjb.com.au wrote: Greetings, As a newbie, starting with Python3, I'm working my way through Mark Summerfield's tkinter examples. In the toolbar, there's lines like: for image, command in ( ('images/filenew.gif', self.fileNew), ('images/fileopen.gif', self.fileOpen), ('images/filesave.gif', self.fileSave), ('images/editadd.gif', self.editAdd), ('images/editedit.gif', self.editEdit), ('images/editdelete.gif', self.editDelete),): image = os.path.join(os.path.dirname(__file__), image) image = tkinter.PhotoImage(file=image) self.toolbar_images.append(image) button = tkinter.Button(toolbar, image=image, command=command) button.grid(row=0, column=len(self.toolbar_images) -1) which are always failing because the icons are in the wrong place and I can't help but wonder if I can put all these little images in the application itself, either as b'whatever' or uuencoded or in svg etc, and then invoke some suitable variation of the image = tkinter.PhotoImage(file=image) or of the button = tkinter.Button(toolbar, image=image, command=command) command ? (I did try help('tkinter.PhotoImage') but didn't spot a magic key (unless it's data=something, format=something)) ... Just dump the contents of the file as a bytestring and use: image = PhotoImage(data=the_byte_string) With no extension, I guess it'll only work with GIF files, as it is the only natively supported image format in tcl/tk (AFAIK...). HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
Re: python sql query in django
On Feb 23, 12:48 pm, Bruno Desthuilliers bdesth.quelquech...@free.quelquepart.fr wrote: May a écrit : (snip) I may not stay with Django. Nope, but your question was about Django. I am seriously looking for whether python can read data from a relational database Of course - as long as there's a Python adapter for your DB. and send to an html template Of course - as long as it's either a Python templating system or there's a Python binding for this system. or do I always need some kind of wrapper/interface such as Rails Uh ? Rails is a Ruby framework. or Django? No, you don't. If you prefer to reinvent the wheel on each and any part of each an any web app you write, please feel free to do so. If this is the wrong group to ask that question Which that question ?-) For question related to Django's ORM, the django group is indeed a better place (as usual: always use the most specific group / maling list / whatever first). If you have questions (like the above) that are about Python itself, you're at the right place. Thanks for all your suggestions. From what I've experienced in Django and now that I know a little more about how Python functions, I will probably use a combination of PHP and Django, instead of trying to get Python to do the web portion of my project. Thanks again! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending Python Questions .....
Ben bnsili...@gmail.com wrote: No, It uses the the S-lang for video, and input control. However, SLAG is more of an abstract layer on top of that. It has a Structures that contains menus and screens (menumodule / screenmodule). One LOADS them up with parameters. such as creating a new menu is like: OpenMenu( Company name, SubSystem, this program name, mode, bottom status display) - Create initial menu structure Addtomenu(Menu Block Set name, DISPLAY line, ID, type of program, password ID ) - add to / update MENU blocks. runMenu() - Displays the whole create menu structure. The Menu structure is done in pull downs and scrollable blocks in a TUI (text User Interface) and using the S-lang screen library is fully mouseable. The screen module works mych the same way, but with the abiltity to open and close and work within Sub Screens. For those who do not know, S-lang is a interpreted language much like Python. However, there is s direth of library modules. The original S-lang started out as library of screen of keyboard modules, but has been expanded My SLAG project does not care in reality WHICH or what language, it is simply handling menu and screen control. So do you want to embed python into your code? I'm still not clear what you are trying to achieve with python, though I have a better idea what SLAG is now! -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Python Image Library IOError - cannot find JPEG decoder?
I've been trying to install the Python Image Library (PIL) on my Mac OSX Leopard laptop, but have been running into some difficulties. I've built the library, using the included setup.py script. The build summary checks out ok, and sounds the option libraries to all be found. I grabbed both libjpeg and freetype2 using fink. PIL 1.1.6 BUILD SUMMARY version 1.1.6 platform darwin 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) [GCC 4.0.1 (Apple Inc. build 5465)] --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok However, I then run the included self test, and 1 out of 57 tests fails. I receive an IOError. Specifically: * Failure in example: _info(Image.open(Images/lena.jpg)) from line #24 of selftest.testimage Exception raised: Traceback (most recent call last): File ./doctest.py, line 499, in _run_examples_inner exec compile(source, string, single) in globs File string, line 1, in module File ./selftest.py, line 22, in _info im.load() File PIL/ImageFile.py, line 180, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File PIL/Image.py, line 375, in _getdecoder raise IOError(decoder %s not available % decoder_name) IOError: decoder jpeg not available 1 items had failures: 1 of 57 in selftest.testimage ***Test Failed*** 1 failures. *** 1 tests of 57 failed. I've followed all of the installation instructions exactly. The build summary reported everything was ok. What could be the problem here. Libjpeg-6b is not accessible? Thank you for any insight you can provide!! -Dario -- http://mail.python.org/mailman/listinfo/python-list
Re: try except question - serious foo bar question, and pulling my hair out :-)
2009/2/24 Grant Edwards inva...@invalid: It works with a person as well as stuffed toys -- but trying to order a person on the internet gets you in a lot more trouble. It's also a little more embarassing when you realize your mistake in front of a person. OTOH, sometimes a person will ask an enlightening question; but, sometimes they just make unhelpfull wisecracks. It's a tough choice. I used to use a baby, which avoids the embarrassment but can be just as problematic to order on the internet. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python AppStore / Marketplace
On 22 Feb, 12:24, Marcel Luethi marcel.lue...@gmail.com wrote: Using my iPhone I suddenly realize how easy it is to find applications in Apple's AppStore. How easy and fast it is to install or de-install an app. My iPhone even checks in the background if there is an upgrade which could be installed painlessly. Yes, but this is just one platform. Can you download these iPhone applications onto Android devices and use them? How would you package your Objective-C (or whatever Apple has mandated) software for Android or Debian or anything else out there? Then I see VMware's Virtual Appliance Marketplace, where you can download already pre-configured appliances for all kind of stuff. You can even download a basic appliance, install and configure your servers and tools - and upload it again, so that others can profit of your work. Unfortunately there's nothing like this in the Python world... That's because you first wrote about platform-specific packaging and now you're writing about language-specific packaging. And it's not as if the former area hasn't been well addressed by Free Software, either, but I suppose that's another discussion to be had. My idea: what about having a beefed up Cheeseshop for Python apps and an accompanying client app kind of iTunes for Python apps? The server side could be easily implemented with any of the current web frameworks. It's simply a management platform for the app packages (descriptions, versions, platforms, licenses, user's comments, number of downloads, ...) and the package files themselves. It should be definitely hosted by the PSF I think. Well, what you're proposing risks exactly the same problems that many other language-specific packaging solutions suffer from: it starts off with specifying platforms, dependencies (which you didn't mention), download files, and ends up with the user downloading huge amounts of stuff that may already be on their system, mostly because such solutions assume that the system doesn't really know anything about what's already installed. Consequences of this may include a lack of decent system-related tools to manage the result of installing stuff: it would be like your iPhone application being installable on Android by being dumped into the filesystem with little regard for existing content and with no obvious strategy for safely removing the application later. It's true that there are other application repositories similar to the VMware service you mention which don't really care about dependencies and just offer self-contained applications for reasons of catering to the lowest common denominator, and perhaps there's a desire to have such services out there, but then again, doing such stuff specifically for Python will lead you into making self-contained applications using those installer technologies, or at least mapping and providing non- Python library dependencies across multiple platforms. Or you could just make it easier for Python projects to provide self-contained applications based on VMware or Free Software alternatives - at least that would allow you to focus on one platform, although the result wouldn't be regarded as a fully integrated cross-platform approach because a virtual machine would be involved. The multi-platform client should be intuitively and elegantly allow app browsing, downloading and installing those Python apps. In that respect it is sort of a Linux package manager (Synaptic, YUM, ...). Why wouldn't you make use of existing system package management, then? But this is only the end-user related stuff. Furthermore it should allow to create new apps (probably based on a previously downloaded base app), package and upload them again (kind of Google AppEngine Launcher). Those base packages should include some basic management framework (for installation and configuration) and hopefully soon after the release of this platform they will be created in a broad variety to allow app developers to choose among many Python-version/ platform/GUI/...-combinations. Well, system packages of Python software typically make some use of distutils to put files in the right places before bundling those files together. The resulting system packages then work within a basic management framework, although I accept that there typically isn't much support for trivial repackaging, although it isn't that difficult to repackage, say, a Debian package and to publish it in your own repository. IMHO an architecture like this would greatly enhance the productivity of the whole Python community by capitalizing the knowledge of many Python specialists. I don't have to find/install/configure all the basic stuff myself (see above) to build my app. But I can concentrate on my app because I'm standing on the shoulders of giants. It isn't hard to find/install/configure the basic stuff in most GNU/ Linux distributions, either. I believe it also would make Python as a great platform more visible to
Re: Unix Change Passwd Python CGI
IMHO That sounds like the biggest security hole I can think of. Anyways you can open a pipe to passwd. to have the change there password. James On Tue, Feb 24, 2009 at 5:19 PM, Derek Tracy trac...@gmail.com wrote: I am using python version 2.5.1 and need to create a python cgi application to allow a user to change their unix password. Apache is running on the same system that needs the password changed. I need to keep security high and can not install additional modules at this time. I just need a general direction to start looking, and I do not have expect installed on the system. Any ideas would be wonderful! R/S -- - Derek Tracy trac...@gmail.com - -- http://mail.python.org/mailman/listinfo/python-list -- http://www.goldwatches.com/ http://www.jewelerslounge.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Metaclass conflict TypeError exception: problem demonstration script
Barak, Ron ron.ba...@lsi.com writes: However, when line 7 is in effect (with line 8 commented out), viz.: $ cat -n metaclass_test01.py | head 1 #!/usr/bin/env python 2 3 import sys 4 import wx 5 import CopyAndPaste 6 7 class ListControl(wx.Frame, CopyAndPaste): If this is the actual source you're running, then CopyAndPaste is a module, not a type, and that causes the conflict. Use CopyAndPaste.CopyAndPaste, or change the import line to read from CopyAndPaste import CopyAndPaste. Or, even better, adhere to recommendations laid down in PEP 8 and you'll avoid confusion between module and class names. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3 and easygui problem
Thanks to all for helping Peter on this. Just a bit of an update... The solution offered in this thread to Peter's original problem is the same as the once I arrived at. There is a bit of discussion about it here: http://pythonconquerstheuniverse.blogspot.com/2009/01/moving-to-python-30-part1.html The current version of EasyGui doesn't run under 3.0, but Peter and I are in contact and we're working on a version that will. (No estimated availablity date yet.) EasyGui is not in PyPI. A semi-significant revision of EasyGui is in the works (no predicted availablity date yet). Once that revision is out the door, I'll look into putting EasyGui into PyPI. Again, thanks to all who participated in this thread. -- Steve Ferg -- http://mail.python.org/mailman/listinfo/python-list
Re: python sql query in django
Thanks for all your suggestions. From what I've experienced in Django and now that I know a little more about how Python functions, I will probably use a combination of PHP and Django, instead of trying to get Python to do the web portion of my project. Thanks again! That sounds like the worst idea. Django's ORM is good when used from within django, because of all the additional goodies like the admin interface. But if you are going to do the webfrontend using PHP, what part is left for django? If it's only the ORM (for whatever you still use that anyway), there are better alternatives - SQLAlchemy, and SQLObject, for Python. They are more powerful and not interwoven with django. If you are going to hand-code the interface in PHP, I fail to see though why you don't do that in Django directly. You are not forced to use the Admin-interface. Diez -- http://mail.python.org/mailman/listinfo/python-list
Accessing callers context from callee method
when i call a method foo from another method func. can i access func context variables or locals() from foo so def func(): i=10 foo() in foo, can i access func's local variables on in this case i Thanks a lot -- Bidegg worlds best auction site http://bidegg.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing callers context from callee method
On Tue, Feb 24, 2009 at 10:53 AM, mobiledream...@gmail.com wrote: when i call a method foo from another method func. can i access func context variables or locals() from foo so def func(): i=10 foo() in foo, can i access func's local variables on in this case i You can, but it's an evil hack that I would avoid if at all possible; there are almost certainly better ways to accomplish whatever your goal is. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
pdftk
Hi Does one know about a python interface to pdftk? Or something similar which can be used to fill a form by fdf data. cheers Reimar -- http://mail.python.org/mailman/listinfo/python-list
Is there any equivalent feature available in Python..?
Hi, Is there any Python equivalent of java jar,can I include all my sources,properties file etc into a single file.Is there anyway in Python that I can run like the following java -jar Mytest.jar --startwebserver How to so something like this in Python? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python AppStore / Marketplace
Steve Holden wrote: And the multiplatform client that should easily and elegantly allow app browsing, downloading and installing those apps would presumably have to account for the many differences in package formats and install requirements between the different platforms. And then you'd also need to re-download the app if you need it on a (sometimes slightly) different platform. Unless the Souq can beat Apple in its own game, by offering Multiversal Binaries that work across hardware platforms, OSes and their versions, GUI frameworks, Python versions and universes. Settling for Downright Obese Binaries if supporting different universes is considered overkill would be OK too. shoulda-include-a-single-asset-8-by-8-shotgun-cross-compiler-ly y'rs Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any equivalent feature available in Python..?
On Tue, Feb 24, 2009 at 11:05 AM, zaheer.ag...@gmail.com wrote: Hi, Is there any Python equivalent of java jar,can I include all my sources,properties file etc into a single file.Is there anyway in Python that I can run like the following java -jar Mytest.jar --startwebserver How to so something like this in Python? It's mostly possible. See http://docs.python.org/library/zipimport.html Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending Python Questions .....
On Feb 24, 11:31 am, Nick Craig-Wood n...@craig-wood.com wrote: Ben bnsili...@gmail.com wrote: No, It uses the the S-lang for video, and input control. However, SLAG is more of an abstract layer on top of that. It has a Structures that contains menus and screens (menumodule / screenmodule). One LOADS them up with parameters. such as creating a new menu is like: OpenMenu( Company name, SubSystem, this program name, mode, bottom status display) - Create initial menu structure Addtomenu(Menu Block Set name, DISPLAY line, ID, type of program, password ID ) - add to / update MENU blocks. runMenu() - Displays the whole create menu structure. The Menu structure is done in pull downs and scrollable blocks in a TUI (text User Interface) and using the S-lang screen library is fully mouseable. The screen module works mych the same way, but with the abiltity to open and close and work within Sub Screens. For those who do not know, S-lang is a interpreted language much like Python. However, there is s direth of library modules. The original S-lang started out as library of screen of keyboard modules, but has been expanded My SLAG project does not care in reality WHICH or what language, it is simply handling menu and screen control. So do you want to embed python into your code? I'm still not clear what you are trying to achieve with python, though I have a better idea what SLAG is now! -- Nick Craig-Wood n...@craig-wood.com --http://www.craig-wood.com/nick Maybe he wants SendKeys? Here's the link just in case: http://pypi.python.org/pypi/SendKeys/0.3 Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: shared lib from python code?
Gabriel Rossetti wrote: Ok, I see, thank you. I thought this was possible since I have used *.pyd files before and from what I had read they were dynamic library files. I guess they must be written in C/C++ then. Thank you for the explanation. Yes, that can be confusing. Unlike .py, .pyc, .pyo, a .pyd is a Windows-only version of a .dll that is called .pyd instead of .dll for technical reasons I have forgotten. The difference is not directly relevant to *Python* programming. -- http://mail.python.org/mailman/listinfo/python-list
Run a linux system command as a superuser, using a python script
I have got postfix installed on my machine and I am updating on of its configuration files programmatically(using python)(on some action). Since any change in the configuration needs a reload, I need to reload postfix to reflect the latest change. How can I do that in a python script. Precisely, I have something like this: import subprocess subprocess.Popen('sudo /etc/init.d/postifx reload') Since this script should be run in no-human environment(on the fly), I cant supply the sudo password or even root password(if needed). Even sudo doesn't have a flag to input the password for the command at the first shot. How do I do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a linux system command as a superuser, using a python script
On Tue, Feb 24, 2009 at 11:38 AM, madhav madhav@gmail.com wrote: I have got postfix installed on my machine and I am updating on of its configuration files programmatically(using python)(on some action). Since any change in the configuration needs a reload, I need to reload postfix to reflect the latest change. How can I do that in a python script. Precisely, I have something like this: import subprocess subprocess.Popen('sudo /etc/init.d/postifx reload') Since this script should be run in no-human environment(on the fly), I cant supply the sudo password or even root password(if needed). Even sudo doesn't have a flag to input the password for the command at the first shot. How do I do this? pexpect may be useful in this situation - http://www.noah.org/wiki/Pexpect Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] Accessing callers context from callee method
when i call a method foo from another method func. can i access func context variables or locals() from foo so def func(): i=10 foo() in foo, can i access func's local variables A. python has statically-nested scoping, so you can do it as long as you: 1. define foo() as an inner function -- its def is contained within func()'s def: def func(): i = 10 def foo(): print i 2. you don't define a variable with the same name locally. in other words, you do have access to func()'s 'i' as long as you don't create another 'i' within foo() -- if you do, only your new local 'i' will be within your scope. B. another alterative is to pass in all of func()'s local variables to foo(): foo(**locals()) this will require you to accept the incoming dictionary in foo() and access the variables from it instead of having them be in foo()'s scope. C. in a related note, your question is similar to that of global vs. local variables. inside a function, you have access to the global as long as you don't define a local using the same name. should you only wish to manipulate the global one, i.e. assign a new value to it instead of creating a new local variable with that name, you would need to use the global keyword to specify that you only desire to use and update the global one. i = 0 def func(): i = 10 in this example, the local 'i' in func() hides access to the global 'i'. in the next code snippet, you state you only want to access/update the global 'i'... IOW, don't create a local one: i = 0 def func(): global i i = 10 D. this doesn't work well for inner functions yet: i = 0 def func(): i = 10 def foo(): i = 20 the 'i' in foo() shadows/hides access to func()'s 'i' as well as the global 'i'. if you issue the 'global' keyword, that only gives you access to the global one: i = 0 def func(): i = 10 def foo(): global i i = 20 you cannot get access to func()'s 'i' in this case. E. however, starting in Python 3.x, you'll be able to do somewhat better with the new 'nonlocal' keyword: i = 0 print('globally, i ==', i) def func(): i = 10 print('in func(), i ==', i) def foo(): nonlocal i i = 20 print('in foo(), i ==', i) foo() print('in func() after calling foo(), i ==', i) func() in this case, foo() modified func()'s 'i'. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 Python Fundamentals, Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any equivalent feature available in Python..?
On Tue, 2009-02-24 at 11:05 -0800, zaheer.ag...@gmail.com wrote: Hi, Is there any Python equivalent of java jar,can I include all my sources,properties file etc into a single file.Is there anyway in Python that I can run like the following java -jar Mytest.jar --startwebserver How to so something like this in Python? Similar but not equal: $ tree mytest mytest |-- __init__.py `-- main.py $ cat mytest/__init__.py if __name__ == '__main__': import sys print sys.argv import mytest.main $ cat mytest/main.py print 'hi mom' $ zip -r mytest.zip mytest adding: mytest/ (stored 0%) adding: mytest/main.py (stored 0%) adding: mytest/__init__.py (deflated 4%) $ PYTHONPATH=mytest.zip python -m mytest --startserver [None, '--startserver'] hi mom -- http://mail.python.org/mailman/listinfo/python-list
Re: more on unescaping escapes
On Feb 23, 7:18 pm, bvdp b...@mellowood.ca wrote: Gabriel Genellina wrote: En Mon, 23 Feb 2009 23:31:20 -0200, bvdp b...@mellowood.ca escribió: Gabriel Genellina wrote: En Mon, 23 Feb 2009 22:46:34 -0200, bvdp b...@mellowood.ca escribió: Chris Rebert wrote: On Mon, Feb 23, 2009 at 4:26 PM, bvdp b...@mellowood.ca wrote: [problem with Python and Windows paths using backslashes] Is there any particular reason you can't just internally use regular forward-slashes for the paths? [...] you are absolutely right! Just use '/' on both systems and be done with it. Of course I still need to use \x20 for spaces, but that is easy. Why is that? \x20 is exactly the same as . It's not like %20 in URLs, that becomes a space only after decoding. I need to use the \x20 because of my parser. I'm reading unquoted lines from a file. The file creater needs to use the form foo\x20bar without the quotes in the file so my parser can read it as a single token. Later, the string/token needs to be decoded with the \x20 converted to a space. So, in my file foo bar (no quotes) is read as 2 tokens; foo\x20bar is one. So, it's not really a problem of what happens when you assign a string in the form foo bar, rather how to convert the \x20 in a string to a space. I think the \\ just complicates the entire issue. Just thinking, if you was reading the string from a file, why were you worried about \\ and \ in the first place? (Ok, you moved to use / so this is moot now). Just cruft introduced while I was trying to figure it all out. Having to figure the \\ and \x20 at same time with file and keyboard input just confused the entire issue :) Having the user set a line like c:\\Program\x20File ... works just fine. I'll suggest he use c:/program\x20files to make it bit simple for HIM, not my parser. Unfortunately, due to some bad design decisions on my part about 5 years ago I'm afraid I'm stuck with the \x20. Thanks. You're confusing the python source with the actual contents of the string. We already do one pass at decoding, which is why \x20 is quite literally no different from a space: '\x20' ' ' However, the interactive interpreter uses repr(x), so various characters that are considered formatting, such as a tab, get reescaped when printing: '\t' '\t' len('\t') 1 It really is a tab that gets stored there, not the escape for one. Finally, if you give python an unknown escape it passes it leaves it as an escape. Then, when the interactive interpreter uses repr(x), it is the backslash itself that gets reescaped: '\P' '\\P' len('\P') 2 list('\P') ['\\', 'P'] What does this all mean? If you want to test your parser with python literals you need to escape them twice, like so: 'c:Program\\x20Filestest' 'c:Program\\x20Filestest' list('c:Program\\x20Filestest') ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] 'c:Program\\x20Filestest'.decode('string-escape') 'c:\\Program Files\\test' list('c:Program\\x20Filestest'.decode('string-escape')) ['c', ':', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 'F', 'i', 'l', 'e', 's', '\\', 't', 'e', 's', 't'] However, there's an easier way: use raw strings, which prevent python from unescaping anything: r'c:\\Program\x20Files\\test' 'c:Program\\x20Filestest' list(r'c:\\Program\x20Files\\test') ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] -- http://mail.python.org/mailman/listinfo/python-list
Re: 'u' Obselete type – it is identical to 'd'. (7)
On Feb 25, 4:48 am, mathieu mathieu.malate...@gmail.com wrote: I did not know where to report that: 'u' Obselete type – it is identical to 'd'. (7) http://docs.python.org/library/stdtypes.html#string-formatting So what's your problem with that? Do you believe that 'u' is not accepted? That 'u' is not identical to 'd' and thus the doc should be rewritten as its behaviour is identical to that of 'd'? That the behaviour of 'u' is NOT identical to that of 'd'? That 'u' should not be documented? That 'u' should not be described as obselete? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3D CAD -- need collaborators, or just brave souls :)
On Feb 20, 3:09 pm, Dotan Cohen dotanco...@gmail.com wrote: Even 3DS or Maya is easier to learn that Blender. Notepad is easier to learn that VI. Not a good program does simple make. And not a good program does complex make either Yoda. Assembly language is very powerful and allows full control down to the processor level. With your logic all programs would be written in assembly. Only problem is with that logic we would be 30 years behind in development of software at this time. Abstraction is paramount to advancement. With abstraction now you can focus on the problem at hand instead of miles of steps just to get to the problem at hand. Human beings are not hardware, we need high levels of abstraction so we can do what we do best... dream, image, and create. -- http://mail.python.org/mailman/listinfo/python-list
Re: pdftk
Reimar Bauer a écrit : Hi Does one know about a python interface to pdftk? Or something similar which can be used to fill a form by fdf data. everyday i use : import os os.system(pdftk.exe source.pdf fill_form data.fdf output output.pdf flatten) and BIM ;) -- http://mail.python.org/mailman/listinfo/python-list
Cross-compiling error when compiling 2.6.1...
I come across the following error: checking for chflags... configure: error: cannot run test program while cross compiling See `config.log' for more details. make-3.81[1]: *** [/nobackup/garrcoop/python_upgrade/contrib/python/obj-mips32/Makefile] Error 1 make-3.81[1]: Leaving directory `/nobackup/garrcoop/python_upgrade' make-3.81: *** [all] Error 2 The blurb from configure that does this test says: # On Tru64, chflags seems to be present, but calling it will # exit Python Basically this testcase (while valid for Tru64) doesn't work with many cross-compilation environments. Couldn't test instead be disabled, but the compilation continue with a warning? Erroring out the build seems like a silly decision... Thanks, -Garrett -- http://mail.python.org/mailman/listinfo/python-list
Re: Python AppStore / Marketplace
Just a few quick questions on your proposed design: 1) What tools, if any, do you propose to help developers package for this platform? 2) How do you plan to deal with applications that change or depend on system-wide settings, ie, conf files, kernel version, or the registry? 3) What advantages do you see this having over, say, porting portage or apt-get? Thanks for your time, Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: python sql query in django
On Feb 24, 10:36 am, Diez B. Roggisch de...@nospam.web.de wrote: Thanks for all your suggestions. From what I've experienced in Django and now that I know a little more about how Python functions, I will probably use a combination of PHP and Django, instead of trying to get Python to do the web portion of my project. Thanks again! That sounds like the worst idea. Django's ORM is good when used from within django, because of all the additional goodies like the admin interface. But if you are going to do the webfrontend using PHP, what part is left for django? If it's only the ORM (for whatever you still use that anyway), there are better alternatives - SQLAlchemy, and SQLObject, for Python. They are more powerful and not interwoven with django. If you are going to hand-code the interface in PHP, I fail to see though why you don't do that in Django directly. You are not forced to use the Admin-interface. Diez Hello Diez, I think Django is fabulous for the admin-interface, a simple text search and template inheritance. I will use Django for all of those. What I'm not getting an answer to and cannot find an example of is a complex search, where I have to retrieve data from multiple tables, combine the data, remove the duplicates, etc between a web page and the database. The code that started this thread is only a small piece of the complex data retrieval I need to do. PHP is great for writing complex SQL queries right in the HTML template and I know exactly what it is doing. -- http://mail.python.org/mailman/listinfo/python-list
Re: more on unescaping escapes
Adam Olsen wrote: On Feb 23, 7:18 pm, bvdp b...@mellowood.ca wrote: Gabriel Genellina wrote: En Mon, 23 Feb 2009 23:31:20 -0200, bvdp b...@mellowood.ca escribió: Gabriel Genellina wrote: En Mon, 23 Feb 2009 22:46:34 -0200, bvdp b...@mellowood.ca escribió: Chris Rebert wrote: On Mon, Feb 23, 2009 at 4:26 PM, bvdp b...@mellowood.ca wrote: [problem with Python and Windows paths using backslashes] Is there any particular reason you can't just internally use regular forward-slashes for the paths? [...] you are absolutely right! Just use '/' on both systems and be done with it. Of course I still need to use \x20 for spaces, but that is easy. Why is that? \x20 is exactly the same as . It's not like %20 in URLs, that becomes a space only after decoding. I need to use the \x20 because of my parser. I'm reading unquoted lines from a file. The file creater needs to use the form foo\x20bar without the quotes in the file so my parser can read it as a single token. Later, the string/token needs to be decoded with the \x20 converted to a space. So, in my file foo bar (no quotes) is read as 2 tokens; foo\x20bar is one. So, it's not really a problem of what happens when you assign a string in the form foo bar, rather how to convert the \x20 in a string to a space. I think the \\ just complicates the entire issue. Just thinking, if you was reading the string from a file, why were you worried about \\ and \ in the first place? (Ok, you moved to use / so this is moot now). Just cruft introduced while I was trying to figure it all out. Having to figure the \\ and \x20 at same time with file and keyboard input just confused the entire issue :) Having the user set a line like c:\\Program\x20File ... works just fine. I'll suggest he use c:/program\x20files to make it bit simple for HIM, not my parser. Unfortunately, due to some bad design decisions on my part about 5 years ago I'm afraid I'm stuck with the \x20. Thanks. You're confusing the python source with the actual contents of the string. We already do one pass at decoding, which is why \x20 is quite literally no different from a space: '\x20' ' ' However, the interactive interpreter uses repr(x), so various characters that are considered formatting, such as a tab, get reescaped when printing: '\t' '\t' len('\t') 1 It really is a tab that gets stored there, not the escape for one. Finally, if you give python an unknown escape it passes it leaves it as an escape. Then, when the interactive interpreter uses repr(x), it is the backslash itself that gets reescaped: '\P' '\\P' len('\P') 2 list('\P') ['\\', 'P'] What does this all mean? If you want to test your parser with python literals you need to escape them twice, like so: 'c:Program\\x20Filestest' 'c:Program\\x20Filestest' list('c:Program\\x20Filestest') ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] 'c:Program\\x20Filestest'.decode('string-escape') 'c:\\Program Files\\test' list('c:Program\\x20Filestest'.decode('string-escape')) ['c', ':', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', ' ', 'F', 'i', 'l', 'e', 's', '\\', 't', 'e', 's', 't'] However, there's an easier way: use raw strings, which prevent python from unescaping anything: r'c:\\Program\x20Files\\test' 'c:Program\\x20Filestest' list(r'c:\\Program\x20Files\\test') ['c', ':', '\\', '\\', 'P', 'r', 'o', 'g', 'r', 'a', 'm', '\\', 'x', '2', '0', 'F', 'i', 'l', 'e', 's', '\\', '\\', 't', 'e', 's', 't'] Thank you. That is very clear. Appreciate your time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3D CAD -- need collaborators, or just brave souls :)
I'm interested. If you are still serious about doing this in two months, send me an email. If you have something put together at that point we can talk about its future. Sound fair? Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a linux system command as a superuser, using a python script
Run the script as root and have it drop privs when it doesn't need them. Or set up a separate daemon to do the rootish parts of it. -- http://mail.python.org/mailman/listinfo/python-list
Problem with environment variables and cx_Oracle
Hello everyone, Here's my setup: OS X (10.5.6 - Intel), Oracle Instant Clinet 10_2, Python 2.6.1, Django trunk I have my Oracle instantclient folder at: /Users/bft228/Library/Oracle/ instantclient_10_2 In my .bash_profile, I have ORACLE_HOME and LD_LIBRARY_PATH specified as: ORACLE_HOME=$HOME/Library/Oracle/instantclient_10_2 export ORACLE_HOME LD_LIBRARY_PATH=$ORACLE_HOME export LD_LIBRARY_PATH When I try to compile cx_Oracle-4.4.1 or 5.0.1, I get an error stating that it cannot find an Oracle installation. setup.py will error here: # try to determine the Oracle home userOracleHome = os.environ.get(ORACLE_HOME) Now, here's where things get wierd... If I: echo $ORACLE_HOME = /Users/bft228/Library/Oracle/ instantclient_10_2 If I: python import os os.environ 'ORACLE_HOME': '/Users/bft228/Library/Oracle/ instantclient_10_2', 'LD_LIBRARY_PATH': '/Users/bft228/Library/Oracle/ instantclient_10_2' If I hard-code the userOracleHome, cx_Oracle will compile, but I'm getting errors wen attempting to connect to Oracle, like: cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle I've been wrestling with this for quite some time. My Oracle person assures me that my user has appropriate permissions for the schema. My Oracle experience is pretty limited, but this seems like it's an issue with the environment on my Mac. Does anyone have any ideas? I would REALLY appreciate some insight. Kind regards, Brandon Taylor Senior Web Developer The University of Texas at Austin -- http://mail.python.org/mailman/listinfo/python-list
Pydev 1.4.4 Released
Hi All, Pydev and Pydev Extensions 1.4.4 have been released -- note that the release already happened 4 days ago... :) Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev: -- This release fixes a critical bug when configuring the interpreter (if no environment variables were specified, it was not possible to configure an interpreter) What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny -- Software Developer Aptana http://aptana.com/python Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a linux system command as a superuser, using a python script
On Feb 24, 11:44 am, Chris Rebert c...@rebertia.com wrote: On Tue, Feb 24, 2009 at 11:38 AM, madhav madhav@gmail.com wrote: I have got postfix installed on my machine and I am updating on of its configuration files programmatically(using python)(on some action). Since any change in the configuration needs a reload, I need to reload postfix to reflect the latest change. How can I do that in a python script. Precisely, I have something like this: import subprocess subprocess.Popen('sudo /etc/init.d/postifx reload') Since this script should be run in no-human environment(on the fly), I cant supply the sudo password or even root password(if needed). Even sudo doesn't have a flag to input the password for the command at the first shot. How do I do this? pexpect may be useful in this situation -http://www.noah.org/wiki/Pexpect Cheers, Chris -- Follow the path of the Iguana...http://rebertia.com I vote down the pexpect, you'd be hardcoding a password. How about adjusting the sudoers file to grant the user of this script sudo on / etc/init.d/postifx or even sudo on your python script. -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-compiling error when compiling 2.6.1...
On Tue, Feb 24, 2009 at 12:55 PM, Garrett Cooper yaneg...@gmail.com wrote: I come across the following error: checking for chflags... configure: error: cannot run test program while cross compiling See `config.log' for more details. make-3.81[1]: *** [/nobackup/garrcoop/python_upgrade/contrib/python/obj-mips32/Makefile] Error 1 make-3.81[1]: Leaving directory `/nobackup/garrcoop/python_upgrade' make-3.81: *** [all] Error 2 The blurb from configure that does this test says: # On Tru64, chflags seems to be present, but calling it will # exit Python Basically this testcase (while valid for Tru64) doesn't work with many cross-compilation environments. Couldn't test instead be disabled, but the compilation continue with a warning? Erroring out the build seems like a silly decision... Thanks, -Garrett I've so far tied this issue down to the chflags, lchflags, and printf with %zd support tests. After commenting out those items things run to completion. -Garrett -- http://mail.python.org/mailman/listinfo/python-list
Re: pdftk
On Feb 24, 12:43 pm, JB zo...@chez.com wrote: Reimar Bauer a écrit : Hi Does one know about a python interface to pdftk? Or something similar which can be used to fill a form by fdf data. everyday i use : import os os.system(pdftk.exe source.pdf fill_form data.fdf output output.pdf flatten) and BIM ;) Reportlab will let you use an existing PDF as a template, letting you use its text layout routines to overly your data on the existing page and output a new document. -- http://mail.python.org/mailman/listinfo/python-list
Re: 'u' Obselete type – it is identical to 'd'. (7)
mathieu wrote: I did not know where to report that: 'u' Obselete type – it is identical to 'd'. (7) http://docs.python.org/library/stdtypes.html#string-formatting Thanks If you google on python bug tracker the first link is the correct one. I don't know what you want to report, but I've reported that obsolete is mispelled: http://bugs.python.org/issue5361 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Getting screen dims platform specific? Say it ain't so!
Hello people, I'm looking for a way to get the screen dimensions (in pixels) using the standard Python library. The only thing I found so far was the following: from win32api import GetSystemMetrics Width = GetSystemMetrics(0) Height = GetSystemMetrics(1) I get an error claiming no module named win32api. It's platform specific anyway, but I thought I would try. Anyone got this? -L -- http://mail.python.org/mailman/listinfo/python-list
Re: 'u' Obselete type – it is identical to 'd'. (7)
On Feb 25, 9:06 am, Steven D'Aprano st...@pearwood.info wrote: mathieu wrote: I did not know where to report that: 'u' Obselete type – it is identical to 'd'. (7) http://docs.python.org/library/stdtypes.html#string-formatting Thanks If you google on python bug tracker the first link is the correct one. I don't know what you want to report, but I've reported that obsolete is mispelled: http://bugs.python.org/issue5361 +1 Own Goal of the Year ... see http://www.yourdictionary.com/library/misspelled.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting screen dims platform specific? Say it ain't so!
On Tuesday 24 February 2009 05:57:52 pm Lionel wrote: from win32api import GetSystemMetrics I'd guess that win32api is patform specific, as in api for win32. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyrie -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting screen dims platform specific? Say it ain't so!
For X systems you can use xwininfo, ie: from commands import getstatusoutput def get_screen_dims(): status, output = getstatusoutput(xwininfo -root) if not status: On Tue, Feb 24, 2009 at 6:53 PM, Luis Zarrabeitia ky...@uh.cu wrote: On Tuesday 24 February 2009 05:57:52 pm Lionel wrote: from win32api import GetSystemMetrics I'd guess that win32api is patform specific, as in api for win32. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyriehttp://profesores.matcom.uh.cu/%7Ekyrie -- http://mail.python.org/mailman/listinfo/python-list -- OpenMigration LLC- Open Source solutions for your business. Visit us at http://OpenMigration.net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting screen dims platform specific? Say it ain't so!
my apologies- hit enter accidentally. anyway, just process the output of that command for the Height: and Width: lines. -- http://mail.python.org/mailman/listinfo/python-list
How do I decode unicode characters in the subject using email.message_from_string()?
Dear python-list, I'm having some trouble decoding an email header using the standard imaplib.IMAP4 class and email.message_from_string method. In particular, email.message_from_string() does not seem to properly decode unicode characters in the subject. How do I decode unicode characters in the subject? I read on the documentation that the email module supports RFC 2047. But is there a way to make imaplib.IMAP4 and email.message_from_string use this protocol? I'm using Python 2.5.2 on Fedora. Perhaps this problem has been fixed already in Python 2.6. RHH -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting screen dims platform specific? Say it ain't so!
On Feb 24, 3:53 pm, Luis Zarrabeitia ky...@uh.cu wrote: On Tuesday 24 February 2009 05:57:52 pm Lionel wrote: from win32api import GetSystemMetrics I'd guess that win32api is patform specific, as in api for win32. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH.http://profesores.matcom.uh.cu/~kyrie Yes, it's platform specific. I was just trying anyway to see if it would work. In a nutshell, what I need is a way to acquire the screen dimensions (in pixels) and its dpi setting. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with environment variables and cx_Oracle
On Feb 24, 2009, at 4:34 PM, Brandon Taylor wrote: Here's my setup: OS X (10.5.6 - Intel), Oracle Instant Clinet 10_2, Python 2.6.1, Django trunk OS X is an important detail here. In my .bash_profile, I have ORACLE_HOME and LD_LIBRARY_PATH specified as: ORACLE_HOME=$HOME/Library/Oracle/instantclient_10_2 export ORACLE_HOME LD_LIBRARY_PATH=$ORACLE_HOME export LD_LIBRARY_PATH Shouldn't this be DYLD_LIBRARY_PATH for Mac? -- http://mail.python.org/mailman/listinfo/python-list
Re: 'u' Obselete type – it is identical to 'd'. (7)
John Machin sjmac...@lexicon.net writes: On Feb 25, 9:06 am, Steven D'Aprano st...@pearwood.info wrote: I don't know what you want to report, but I've reported that obsolete is mispelled: +1 Own Goal of the Year ... see http://www.yourdictionary.com/library/misspelled.html Not so notable. It's merely one more incident of the law of communication variously known as McKean's Law, Skitt's Law, and Muphry's Law URL:http://en.wikipedia.org/wiki/Muphry%27s_law. -- \ “I have never made but one prayer to God, a very short one: ‘O | `\ Lord, make my enemies ridiculous!’ And God granted it.” | _o__)—Voltaire | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting screen dims platform specific? Say it ain't so!
Lionel wrote: Yes, it's platform specific. I was just trying anyway to see if it would work. In a nutshell, what I need is a way to acquire the screen dimensions (in pixels) and its dpi setting. This should work on all platforms: from Tkinter import * r = Tk() r.withdraw() r.winfo_screenheight() r.winfo_screenwidth() r.winfo_pixels('1i') Regards, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting screen dims platform specific? Say it ain't so!
On Tuesday 24 February 2009 07:12:36 pm Lionel wrote: In a nutshell, what I need is a way to acquire the screen dimensions (in pixels) and its dpi setting. This is a guess, and a guess only. What do you want to know it for? If it is for painting something on the screen, maybe (just maybe - I'm guessing here big time), whatever API you are using for painting can be used for getting the dimensions of the drawing device. I don't even know if GTK or Qt have that feature, but you should look into it. If the same api you will use for painting provides that functionality, then it would be kind of irrelevant if it is on the stdlib or not. Of course, this only applies if you want to paint and your api provides that info. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyrie -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I decode unicode characters in the subject using email.message_from_string()?
On Feb 25, 11:07 am, Roy H. Han starsareblueandfara...@gmail.com wrote: Dear python-list, I'm having some trouble decoding an email header using the standard imaplib.IMAP4 class and email.message_from_string method. In particular, email.message_from_string() does not seem to properly decode unicode characters in the subject. How do I decode unicode characters in the subject? You don't. You can't. You decode str objects into unicode objects. You encode unicode objects into str objects. If your input is not a str object, you have a problem. I'm no expert on the email package, but experts don't have crystal balls, so let's gather some data for them while we're waiting for their timezones to align: Presumably your code is doing something like: msg = email.message_from_string(a_string) Please report the results of print repr(a_string) and print type(msg) print msg.items() and tell us what you expected. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list