Proxysite open facebook ,myaspace,.....etc
Proxysite open facebook ,myaspace,.etc http://proxypop.110mb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
Hendrik van Rooyen wrote: there would be no way for a language to change and grow, if it were literally true that you cannot think of something that you have no word for. From my own experience, I know that it's possible for me to think about things that I don't have a word for. An example occured once when I was developing a 3D game engine, and I was trying to think of a name for the thing that exists where two convex polyhedra share a face, except that the face is missing (it's hard to explain even using multiple words). I couldn't think of any word that fully expressed the precise concept I had in mind. Yet I was clearly capable of thinking about it, otherwise I wouldn't have noticed that I was missing a word! So in my humble opinion, the strong form of the Sapir-Whorf hypothesis is bunk. :-) -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Gabriel Genellina skrev: En Fri, 18 Sep 2009 10:55:47 -0300, Johan Grönqvist escribió: Summarizing the answers, it seems that I will try to follow three suggestions: 3) If I define a few values intended to be used very locally, delete those after use. Why bother? Unless they're big objects and you want to ensure they get deleted as soon as possible. To ease debugging. Perhaps the problem only appears because I use longer functions than recommended for python, but I have functions containing 2 to 4 loops, with several if-clause each, where the different parts use very similar variable names, like x, y, z, dr, dr_2, dr_3 etc. None of the code fragments uses all of the names, but every fragment uses some of them. I have had typos that incorrectly reused values from a previous fragment. In those cases, it would have been much easier to debug a raised exception due to using an undefined name, than to debug a slightly incorrect result due to some if-clause of some loop computing with an incorrect value. Regards Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Sean DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I like this solution. This also minimizes the extra code if I would want to explicitly delete the bindings, as I would only need one line to delete the Namespace object. Thanks! Johan -- http://mail.python.org/mailman/listinfo/python-list
Sunday 20th Global Python Mtg via VOIP - BerkeleyTIP - for forwarding
Get a VOIP headset, Install VOIP client SW, & join the global Python meeting this Sunday Sept 20, 12N-3P Pacific Daylight Savings Time (UTC-8), 3P-6P Eastern, (7P-10P UTC?) http://sites.google.com/site/berkeleytip/remote-attendance Lots of great, exciting new things for Python users, as we start Year 2 of the Global FSW GNU(Linux)/BSD, Free HW, Free Culture, TIP meetings: TIP = Talks, Installfest, Project/Programing Party. Educational, Productive, Social. Join with the meeting from your home via VOIP, or create a local meeting at your local college wifi cafe. = Quick announcement. We're starting up BTIP year 2, for the 2009-10 school year. http://sites.google.com/site/berkeleytip/home September Videos: Puppet language, Python mystery talks, CampKDE http://sites.google.com/site/berkeleytip/talk-videos This year 2 we'll be focusing on 1) Inviting UC Berkeley students via poster/flyers 2) Getting local meetings going at California colleges 3) Getting invitations out to more American countries 4) Getting topic groups (OLPC, Python, KDE & GNOME, BSD, Ubuntu, etc) having simultaneous meetings. 5) Improving our VOIP server, perhaps upgrading to FreeSwitch. == Come join the Sept 20 Sunday meeting, get on voip, chat, discuss the videos, work on your own projects & share them with others, help educate students, & help work on the group projects. Join #berkeleytip on irc.freenode.net, & we'll help you get your VOIP HW & SW working. :) Join the mailing lists & say hi, tell us what you are interested in. http://groups.google.com/group/BerkTIPGlobal You are invited to forward this message anywhere it would be welcomed. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
On Saturday 19 September 2009 09:12:34 greg wrote: > From my own experience, I know that it's possible for me to > think about things that I don't have a word for. An example > occured once when I was developing a 3D game engine, and > I was trying to think of a name for the thing that exists > where two convex polyhedra share a face, except that the > face is missing (it's hard to explain even using multiple > words). Yikes! If I follow you, it is a bit like having a hollow dumb-bell with a hollow handle of zero length, and wanting a word for that opening between the knobs. I do not think that you are likely to find a word in *any* language for that - I would posit that it is too seldom encountered to deserve one. What does a concave polyhedrum look like? *weg* > > I couldn't think of any word that fully expressed the precise > concept I had in mind. Yet I was clearly capable of thinking > about it, otherwise I wouldn't have noticed that I was missing > a word! > > So in my humble opinion, the strong form of the Sapir-Whorf > hypothesis is bunk. :-) That is probably true, but on the other hand, it is not totally rubbish either, as it is hard to think of stuff you have never heard of, whether you have an undefined word for it or not. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Podcast catcher in Python
Chuck wrote: On Sep 12, 3:37 pm, Chuck wrote: On Sep 11, 9:54 pm, Chris Rebert wrote: On Fri, Sep 11, 2009 at 7:43 PM, Chuck wrote: Does anyone know how I should read/download the mp3 file, and how I should write/save it so that I can play it on a media player such as Windoze media player? Excuse my ignorance, but I am a complete noob at this. I downloaded the mp3, and I got a ton of hex, I think, but it could've been unicode. urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve Cheers, Chris Thanks Chris! I will play around with this. I am using Python 3.1, but I can't figure out why I can't use xml.dom.minidom. Here is my code: from xml.dom.minidom import parse, parseString url =http://minnesota.publicradio.org/tools/podcasts/ grammar_grater.xml' #just for test purposes doc =arse(url) #I have also tried parseString(url), not to mention a million other methods from xml.Etree, xml.sax etc... all to no avail What the heck am I doing wrong? How can I get this xml file and use the toprettyxml() method. Or something, so I can parse it. I don't have any books and the documentation for Python kind of sucks. I am a complete noob to Python and internet programming. (I'm sure that is obvious :) ) Thanks! Charlie Wrong? You didn't specify your OS environment, you didn't show the error message (and traceback), you posted an apparently unrelated question in the same thread (there's no XML inside a mp3 file). xml.dom.minidom.parse() takes a filename or a 'file' object as its first argument. You gave it a URL, so it complained. You can fix that either by using urllib.urlopen() or by separately copying the data to a local file and using its filename here. In general, I'd recommend against testing new code live against the internet, since errors can occur from the vagaries of the internet as well as from bugs in your code. Sometimes it's hard to tell the difference when the symptoms change each time you run. So I'd download the xml data that you want to test with to a local file, and test out your parsing logic against that copy. In fact, first testing will probably be against a simplified version of that copy. How do you download the file? Well, if you're using Firefox, you can browse to that page, and do View->Source. Then copy/paste that text into a text editor, and save it locally. Something similar probably works in other browsers, maybe even IE. Or you can use urlretrieve, as suggested earlier in this thread. But I'd make that a separate script, so that you can separate the bugs in downloading from the bugs in parsing. After everything mostly works, you can think about combining them. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Johan Grönqvist wrote: Sean DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I like this solution. This also minimizes the extra code if I would want to explicitly delete the bindings, as I would only need one line to delete the Namespace object. Thanks! Johan Even simpler solution for most cases, use longer names. If the name means something in the local context, and the next context is different, you presumably will use a deliberately different name. In your earlier example, if you called them row and column, you ought to notice if you used row instead of column in the later "scope". One thing people don't notice when they ask the compiler to catch all these types of problems is that there are lots of things the compiler can't check. In Python if you delete a previous attribute, you'll get an error when trying to read that attribute, but not when trying to write it. Because as soon as you write it, you're declaring it again. I spent years in C++ and Java environments, as well as many other languages that enforced some of these rules. But once you get used to the notion that the system won't check you, you're less likely to fall into the traps that always remain in those other languages -- write your own code defensively. And that means that for anything bigger than throw-away samples, use real names for things., I spent time years ago in Forth, where a name could be almost anything (no embedded spaces), and where syntax in the language was almost non-existent, and you could define first class language constructs inline, no sweat. It really freed the mind to think about the problem, instead of the language and its idiosyncracies. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Granularity of OSError
Grant Edwards wrote: On 2009-09-19, Christian Heimes wrote: kj wrote: For example, LBYL would look like this: if os.path.isfile(some_file): os.unlink(some_file) In contrast, EAFP would look like this: try: os.unlink(some_file) except OSError: pass The two version aren't equal. The first one suffers from a race condition which may lead to a severe security issue. The file may be gone or replaced by a different file in the time span between the check and the call to unlink(). IOW, just be cause you look before you leap, it doesn't mean you're not going to land on anybody and have to ask for forgiveness afterwards. Since you always have to handle the error case, there's not much point in checking first unless the error case has bad side-effects that you're trying to avoid. In this case, attempting to unlink a non-existent file has no bad side-effects, so there's no point in checking before the unlink. It doesn't mean that LBYL is always a bad idea. If, for example, you're going to copy a file, it's a good idea to check beforehand that there's enough space available for the copy. There might be other process changing the amount of freespace available, but it's still a reasonable check to do. -- http://mail.python.org/mailman/listinfo/python-list
How to install pysqlite?
Hi all, I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following: gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar cd pysqlite-2.5.5 python setup.py install At the last step I have a problem. I get the following error message: error: command 'gcc' failed with exit status 1 I found that other peoples also had this problem. For example here: http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line). May be I should change some paths in "setup.cfg"? At the moment I have there: #define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION And if I type "which sqlite3" I get: /usr/bin/sqlite3 Can anybody pleas help me with that problem. Thank you in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter - Text - bullets
> Something like this maybe?
>
> from Tkinter import *
>
> root = Tk()
> txt = Text(root, wrap='word')
> txt.pack()
>
> txt.tag_configure('text_body', font=('Times', 18), lmargin1=0,
> lmargin2=0)
> txt.tag_configure('bulleted_list', font=('Times', 18), lmargin1='10m',
> lmargin2='15m', tabs=['15m'])
>
> txt.insert(END, u"This is a normal paragraph. Let's make it a bit long
> to see that it wraps as expected.\n", 'text_body')
> txt.insert(END, u"\u00B7\tThis is the first item in the list.\n",
> 'bulleted_list')
> txt.insert(END, u"\u00B7\tThis is the second item in the list. Let's
> make this one quite long too to see how it wraps.\n", 'bulleted_list')
Thank you very much!
However, the result is not that pretty as I have expected. The bullets
are really small. When separating bullet and text then I can increase
the font size for the bullet but then it does not fit to the text -
vertical alignment is wrong. Also it's pretty unhandy to adjust the
margins so that the text continues on next line starting at the same
position as the first character from previous line.
But it is a starting. I will check whether it is possible to place an
image for a bullet. The size and position handling will be still there
then - I think so.
Also note: The tab value from your example has not been accepted (s.th
like. "invalid screen distance")
--
http://mail.python.org/mailman/listinfo/python-list
Finding application data after install - a solution?
Hi all,
reliably finding distribution data from your program seems to be an
unsolved issue for programs packaged with distutils.
I have seen a lot of code that manipulates mod.__file__ to solve this
problem, but this *will* break for some installation schemes and has the
following problems:
* it breaks if the user specified '--install-data' to have a different
value than '--install-{pure,plat}lib'
* it makes the life of linux distribution package maintainers
unneccessarily hard, because they have to patch your code so it works
with their file system hierarchy.
* it does not work inside eggs
* it is ugly ;-)
Good news everyone! I spend some time to solve this problems and would
like to share my snippet and ask for comments.
The idea is to fill a python module 'build_info.py' with installation
prefix information *at build time* and access the data within that
module.
--- snip ---
from distutils.command.build_py import build_py as _build_py
from types import StringType, ListType, TupleType
import distutils.core as core
import sys
import os.path
import string
class build_py(_build_py):
"""build_py command
This specific build_py command will modify module 'build_config' so that it
contains information on installation prefixes afterwards.
"""
def build_module (self, module, module_file, package):
if type(package) is StringType:
package = string.split(package, '.')
elif type(package) not in (ListType, TupleType):
raise TypeError, \
"'package' must be a string (dot-separated), list, or tuple"
if ( module == 'build_info' and len(package) == 1 and package[0] ==
'mwdb'):
iobj = self.distribution.command_obj['install']
with open(module_file, 'w') as module_fp:
module_fp.write('# -*- coding: UTF-8 -*-\n\n')
module_fp.write("DATA_DIR = '%s'\n"%(
os.path.join(iobj.install_data, 'share')))
module_fp.write("LIB_DIR = '%s'\n"%(iobj.install_lib))
module_fp.write("SCRIPT_DIR = '%s'\n"%(iobj.install_scripts))
_build_py.build_module(self, module, module_file, package)
core.setup(name='foo',
cmdclass={'build_py': build_py},
...
)
--- snip ---
This works for installers based on distutils and those based on
setuptools and is IMHO a much cleaner and nicer solution than having to
use a complicated API that relies on externally managed information or
__file__ hacks.
Before you copy this i should note that i plan to use string templates
within 'build_info' and just substitute the wanted information and not
generate the whole file from scratch.
The module detection logic and exception handling might need some work
as well. ;-)
I have the following questions:
1. Is the distutils 'API' i use here likely to break?
2. Can you think of a better way to do this?
with kind regards
Wolodja Wentland
signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list
control CPU usage
Hi, When I am running a loop for a long time, calculating heavily, the CPU usage is at 100%, making the comp not so responsive. Is there a way to control the CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help although CPU usage level is reduced, but it's unstable. Regards, W.J.F. -- http://mail.python.org/mailman/listinfo/python-list
Re: Podcast catcher in Python
On Sep 19, 7:40 am, Dave Angel wrote: > Chuck wrote: > > On Sep 12, 3:37 pm, Chuck wrote: > > >> On Sep 11, 9:54 pm, Chris Rebert wrote: > > >>> On Fri, Sep 11, 2009 at 7:43 PM, Chuck wrote: > > Does anyone know how I should read/download the mp3 file, and how I > should write/save it so that I can play it on a media player such as > Windoze media player? Excuse my ignorance, but I am a complete noob > at this. I downloaded the mp3, and I got a ton of hex, I think, but > it could've been unicode. > > >>> urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve > > >>> Cheers, > >>> Chris > > >> Thanks Chris! I will play around with this. > > > I am using Python 3.1, but I can't figure out why I can't use > > xml.dom.minidom. Here is my code: > > > from xml.dom.minidom import parse, parseString > > url =http://minnesota.publicradio.org/tools/podcasts/ > > grammar_grater.xml' #just for test purposes > > > doc =arse(url) #I have also tried parseString(url), not to mention > > a million other methods from xml.Etree, xml.sax etc... all to no > > avail > > > What the heck am I doing wrong? How can I get this xml file and use > > the toprettyxml() method. Or something, so I can parse it. I don't > > have any books and the documentation for Python kind of sucks. I am a > > complete noob to Python and internet programming. (I'm sure that is > > obvious :) ) > > > Thanks! > > > Charlie > > Wrong? You didn't specify your OS environment, you didn't show the > error message (and traceback), you posted an apparently unrelated > question in the same thread (there's no XML inside a mp3 file). > > xml.dom.minidom.parse() takes a filename or a 'file' object as its first > argument. You gave it a URL, so it complained. You can fix that either > by using urllib.urlopen() or by separately copying the data to a local > file and using its filename here. > > In general, I'd recommend against testing new code live against the > internet, since errors can occur from the vagaries of the internet as > well as from bugs in your code. Sometimes it's hard to tell the > difference when the symptoms change each time you run. > > So I'd download the xml data that you want to test with to a local file, > and test out your parsing logic against that copy. In fact, first > testing will probably be against a simplified version of that copy. > > How do you download the file? Well, if you're using Firefox, you can > browse to that page, and do View->Source. Then copy/paste that text > into a text editor, and save it locally. Something similar probably > works in other browsers, maybe even IE. > > Or you can use urlretrieve, as suggested earlier in this thread. But > I'd make that a separate script, so that you can separate the bugs in > downloading from the bugs in parsing. After everything mostly works, > you can think about combining them. > > DaveA Okay, that makes sense. I will try that. Essentially, what I am trying to learn by just reading articles on the web is how to access info on the web using Python, i.e. weather data, podcasts, etc... I have never done it before in any language. So, I am trying to do something that I've never done before with a language I barely know. Can be very frustrating. :( Thanks for all the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Podcast catcher in Python
On Sep 19, 7:40 am, Dave Angel wrote: > Chuck wrote: > > On Sep 12, 3:37 pm, Chuck wrote: > > >> On Sep 11, 9:54 pm, Chris Rebert wrote: > > >>> On Fri, Sep 11, 2009 at 7:43 PM, Chuck wrote: > > Does anyone know how I should read/download the mp3 file, and how I > should write/save it so that I can play it on a media player such as > Windoze media player? Excuse my ignorance, but I am a complete noob > at this. I downloaded the mp3, and I got a ton of hex, I think, but > it could've been unicode. > > >>> urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve > > >>> Cheers, > >>> Chris > > >> Thanks Chris! I will play around with this. > > > I am using Python 3.1, but I can't figure out why I can't use > > xml.dom.minidom. Here is my code: > > > from xml.dom.minidom import parse, parseString > > url =http://minnesota.publicradio.org/tools/podcasts/ > > grammar_grater.xml' #just for test purposes > > > doc =arse(url) #I have also tried parseString(url), not to mention > > a million other methods from xml.Etree, xml.sax etc... all to no > > avail > > > What the heck am I doing wrong? How can I get this xml file and use > > the toprettyxml() method. Or something, so I can parse it. I don't > > have any books and the documentation for Python kind of sucks. I am a > > complete noob to Python and internet programming. (I'm sure that is > > obvious :) ) > > > Thanks! > > > Charlie > > Wrong? You didn't specify your OS environment, you didn't show the > error message (and traceback), you posted an apparently unrelated > question in the same thread (there's no XML inside a mp3 file). > > xml.dom.minidom.parse() takes a filename or a 'file' object as its first > argument. You gave it a URL, so it complained. You can fix that either > by using urllib.urlopen() or by separately copying the data to a local > file and using its filename here. > > In general, I'd recommend against testing new code live against the > internet, since errors can occur from the vagaries of the internet as > well as from bugs in your code. Sometimes it's hard to tell the > difference when the symptoms change each time you run. > > So I'd download the xml data that you want to test with to a local file, > and test out your parsing logic against that copy. In fact, first > testing will probably be against a simplified version of that copy. > > How do you download the file? Well, if you're using Firefox, you can > browse to that page, and do View->Source. Then copy/paste that text > into a text editor, and save it locally. Something similar probably > works in other browsers, maybe even IE. > > Or you can use urlretrieve, as suggested earlier in this thread. But > I'd make that a separate script, so that you can separate the bugs in > downloading from the bugs in parsing. After everything mostly works, > you can think about combining them. > > DaveA Oh yeah! I am using Windows XP. -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
On Sep 19, 9:17 am, kakarukeys wrote: > Hi, > > When I am running a loop for a long time, calculating heavily, the CPU > usage > is at 100%, making the comp not so responsive. Is there a way to > control the > CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help > although CPU usage level is reduced, but it's unstable. > > Regards, > W.J.F. If you are on linux, you can use the 'nice' command. It will still take 100%, but will give it up to other processes that need to use the cpu. nice -n 19
Re: How to install pysqlite?
Roman Gorbunov schrieb: Hi all, I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following: gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar cd pysqlite-2.5.5 python setup.py install At the last step I have a problem. I get the following error message: error: command 'gcc' failed with exit status 1 Please show us the *whole* error. Diez -- http://mail.python.org/mailman/listinfo/python-list
python profiling for a XML parser program
I have a python program doing XML data prasing and write the result to 2 data files; which will be loaded to MySQL. I ran this. $ python dealmaker.py ... read data loop through records ... XML parsing ... write to file1.dat ... write to file2.date done Is there a python profiler just like for C program? And tell me which functions or modules take a long time. Can you show me URL or link on doing this task? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Podcast catcher in Python
On Sep 19, 7:40 am, Dave Angel wrote: > Chuck wrote: > > On Sep 12, 3:37 pm, Chuck wrote: > > >> On Sep 11, 9:54 pm, Chris Rebert wrote: > > >>> On Fri, Sep 11, 2009 at 7:43 PM, Chuck wrote: > > Does anyone know how I should read/download the mp3 file, and how I > should write/save it so that I can play it on a media player such as > Windoze media player? Excuse my ignorance, but I am a complete noob > at this. I downloaded the mp3, and I got a ton of hex, I think, but > it could've been unicode. > > >>> urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve > > >>> Cheers, > >>> Chris > > >> Thanks Chris! I will play around with this. > > > I am using Python 3.1, but I can't figure out why I can't use > > xml.dom.minidom. Here is my code: > > > from xml.dom.minidom import parse, parseString > > url =http://minnesota.publicradio.org/tools/podcasts/ > > grammar_grater.xml' #just for test purposes > > > doc =arse(url) #I have also tried parseString(url), not to mention > > a million other methods from xml.Etree, xml.sax etc... all to no > > avail > > > What the heck am I doing wrong? How can I get this xml file and use > > the toprettyxml() method. Or something, so I can parse it. I don't > > have any books and the documentation for Python kind of sucks. I am a > > complete noob to Python and internet programming. (I'm sure that is > > obvious :) ) > > > Thanks! > > > Charlie > > Wrong? You didn't specify your OS environment, you didn't show the > error message (and traceback), you posted an apparently unrelated > question in the same thread (there's no XML inside a mp3 file). > > xml.dom.minidom.parse() takes a filename or a 'file' object as its first > argument. You gave it a URL, so it complained. You can fix that either > by using urllib.urlopen() or by separately copying the data to a local > file and using its filename here. > > In general, I'd recommend against testing new code live against the > internet, since errors can occur from the vagaries of the internet as > well as from bugs in your code. Sometimes it's hard to tell the > difference when the symptoms change each time you run. > > So I'd download the xml data that you want to test with to a local file, > and test out your parsing logic against that copy. In fact, first > testing will probably be against a simplified version of that copy. > > How do you download the file? Well, if you're using Firefox, you can > browse to that page, and do View->Source. Then copy/paste that text > into a text editor, and save it locally. Something similar probably > works in other browsers, maybe even IE. > > Or you can use urlretrieve, as suggested earlier in this thread. But > I'd make that a separate script, so that you can separate the bugs in > downloading from the bugs in parsing. After everything mostly works, > you can think about combining them. > > DaveA Okay, I have tried to use urllib.request.urlretrieve() to download an mp3, but my cursor just sits and blinks at me. This a small file, so it should take more that a few minutes. Hmmm? Here is my code: url = 'http://download.publicradio.org/podcast/minnesota/news/programs/ 2009/09/10/grammar_20090910_64.mp3' file = 'C:\\Documents and Settings\\Compaq_Owner\\Desktop\ \GramGrate.mp3' import urllib.request b4 = urllib.request.urlretrieve(url, file) at this point, the cursor just sits and blinks forever. Any ideas? I really appreciate this guys. -- http://mail.python.org/mailman/listinfo/python-list
Re: Podcast catcher in Python
Never mind, guys I finally got things working. Woo hoo -- http://mail.python.org/mailman/listinfo/python-list
Re: python profiling for a XML parser program
MacRules schrieb: I have a python program doing XML data prasing and write the result to 2 data files; which will be loaded to MySQL. I ran this. $ python dealmaker.py ... read data loop through records ... XML parsing ... write to file1.dat ... write to file2.date done Is there a python profiler just like for C program? And tell me which functions or modules take a long time. Can you show me URL or link on doing this task? Google dead today? http://www.google.com/search?q=python+profiler&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:de-DE:official&client=firefox-a First hit. It's build-in already. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: python profiling for a XML parser program
On 19 Sep, 21:19, MacRules wrote: > > Is there a python profiler just like for C program? > And tell me which functions or modules take a long time. > > Can you show me URL or link on doing this task? Having already looked at combining Python profilers with KCachegrind (as suggested by Andrew Dalke at EuroPython 2007), I discovered the following discussion about the tools required: http://ddaa.net/blog/python/lsprof-calltree I found the following script very convenient to generate profiler output: http://www.gnome.org/~johan/lsprofcalltree.py You can then visualise the time spent by just passing the output file to KCachegrind: http://kcachegrind.sourceforge.net/html/Home.html The map of time spent in each function is extremely useful, I find. Paul -- http://mail.python.org/mailman/listinfo/python-list
on package import, have it conditionally import a subpackage
Hello everyone,
I'd like to ba able to import a package and have it's __init__
conditionally import a subpackage. Suppose that you have this structure :
mybase/
mybase/__init__.py
mybase/mypkg
mybase/mypkg/__init__.py
mybase/mypkg/module0.py
mybase/mypkg/type1
mybase/mypkg/type1/__init__.py
mybase/mypkg/type1/module1.py
mybase/mypkg/type1/module2.py
mybase/mypkg/type2
mybase/ mypkg/type2/__init__.py
mybase/ mypkg/type2/module1.py
mybase/ mypkg/type2/module2.py
I'd like to do something like th following in my code
>>> import mybase
>>> mybase.setType("type1")
>>> from mybase.mypkg import module0, module1, module2
>>> module0.__file__
'mybase/mypkg/module0.pyc'
>>> module1.__file__
'mybase/mypkg/type1/module1.pyc'
>>> module2.__file__
'mybase/mypkg/type1/module2.pyc'
but I can't figure out how to do this.
Thank you,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to install pysqlite?
> I am trying to install pysqlite (Python interface to the SQLite). I > downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I > did the following: > > gunzip pysqlite-2.5.5.tar.gz > tar xvf pysqlite-2.5.5.tar > cd pysqlite-2.5.5 > python setup.py install > > At the last step I have a problem. I get the following error message: > error: command 'gcc' failed with exit status 1 > > I found that other peoples also had this problem. For example here: > http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html > > As far as I understood in the person had a problem because sqlite2 was > not installed. But in my case, I have sqlite3 (I can run it from > command line). > > May be I should change some paths in "setup.cfg"? At the moment I have > there: > #define= > #include_dirs=/usr/local/include > #library_dirs=/usr/local/lib > libraries=sqlite3 > define=SQLITE_OMIT_LOAD_EXTENSION > > And if I type "which sqlite3" I get: > /usr/bin/sqlite3 > > Can anybody pleas help me with that problem. What version of python are you using? >From 2.5 onward python already includes pysqlite. Try 'import sqlite3'. Python 2.5.1 includes pysqlite 2.3.2 while python 2.6.1 includes pysqlite 2.4.1 and python 3.0 includes also pysqlite 2.4.1. You only need to install pysqlite separately if you explicitly need the newer pysqlite version. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Comparison of parsers in python?
Hi, I did a google search and found various parser in python that can be used to parse different files in various situation. I don't see a page that summarizes and compares all the available parsers in python, from simple and easy-to-use ones to complex and powerful ones. I am wondering if somebody could list all the available parsers and compare them. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
>> the pyjamas project is taking a slightly different approach to achieve >> this same goal: beat the stuffing out of the pyjamas compiler, rather >> than hand-write such large sections of code in pure javascript, and >> double-run regression tests (once as python, second time converted to >> javascript under pyv8run, d8 or spidermonkey). >> >> anyway, just thought there might be people who would be intrigued (or >> horrified enough to care what's being done in the name of computer >> science) by either of these projects. > > I've added pyjamas to the implementations page on the Python Wiki in > the compilers section: > > http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. Does this make it a 'python implementation'? That would be news to me but I've been wrong many times before. Cheers, Daniel > The Skulpt implementation, already listed by Cameron Laird on his page > of Python implementations, is now also present, although using it is a > bit like using various 8-bit microcomputer emulators which assume a UK > keyboard and ignore the "replacement" keys on my own non-UK keyboard. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: python profiling for a XML parser program
Paul Boddie wrote: On 19 Sep, 21:19, MacRules wrote: Is there a python profiler just like for C program? And tell me which functions or modules take a long time. Can you show me URL or link on doing this task? Having already looked at combining Python profilers with KCachegrind (as suggested by Andrew Dalke at EuroPython 2007), I discovered the following discussion about the tools required: http://ddaa.net/blog/python/lsprof-calltree I found the following script very convenient to generate profiler output: http://www.gnome.org/~johan/lsprofcalltree.py You can then visualise the time spent by just passing the output file to KCachegrind: http://kcachegrind.sourceforge.net/html/Home.html The map of time spent in each function is extremely useful, I find. Paul Paul is better than Google. Thanks for the info, I will take a look. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a local variable scope.
Dave Angel wrote: Johan Grönqvist wrote: DiZazzo skrev: I would do something like this: class Namespace(object): ... pass ... n = Namespace() n.f = 2 n.g = 4 print f Traceback (most recent call last): File "", line 1, in ? NameError: name 'f' is not defined print n.f 2 I like this solution. This also minimizes the extra code if I would want to explicitly delete the bindings, as I would only need one line to delete the Namespace object. Even simpler solution for most cases, use longer names. If the name means something in the local context, and the next context is different, you presumably will use a deliberately different name. In your earlier example, if you called them row and column, you ought to notice if you used row instead of column in the later "scope". One thing people don't notice when they ask the compiler to catch all these types of problems is that there are lots of things the compiler can't check. Well said. One of the things I *love* about Python is that it doesn't try to do my programming for me. For the mistakes we inevitably make, good test suites are incredibly useful. Still, and just for fun, the following is at least mildly entertaining (but then, I am easily amused :) class micro_scope(object): def __enter__(self): return self def __exit__(self, type, value, traceback): if type is value is traceback is None: self.__dict__.clear() with micro_scope() as m: m.this = 'that' m.value = 89 for m.i in range(10): do_something_with(m.i) m.value #exception raised here, as m.value no longer exists Don't worry, Steven, I'll never actually use that! ;-) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
kakarukeys wrote: Hi, When I am running a loop for a long time, calculating heavily, the CPU usage is at 100%, making the comp not so responsive. Is there a way to control the CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help although CPU usage level is reduced, but it's unstable. Regards, W.J.F. Controlling a task's scheduling is most definitely OS-dependent., so you need to say what OS you're running on. And whether it's a multi-core and or duo processor. In Windows, there is a generic way to tell the system that you want to give a boost to whatever task has the user focus (generally the top-window on the desktop). On some versions, that's the default, on others, it's not. You change it from Control Panel. I'd have to go look to tell you what applet, but I don't even know if you're on Windows. In addition, a program can adjust its own priority, much the way the Unix 'nice' command works. You'd use the Win32 library for that. And as you already tried, you can add sleep() operations to your application. But if you're looking at the task list in the Windows Task Manager, you aren't necessarily going to see what you apparently want. There's no way to programmatically tell the system to use a certain percentage for a given task. If there's nothing else to do, then a low priority task is still going to get nearly 100% of the CPU. Good thing. But even if there are other things to do, the scheduling is a complex interaction between what kinds of work the various processes have been doing lately, how much memory load they have, and what priority they're assigned. If you just want other processes to be "responsive" when they've got the focus, you may want to make that global setting. But you may need to better define "responsive" and "unstable." DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
Daniel Fetchinson wrote: the pyjamas project is taking a slightly different approach to achieve this same goal: beat the stuffing out of the pyjamas compiler, rather than hand-write such large sections of code in pure javascript, and double-run regression tests (once as python, second time converted to javascript under pyv8run, d8 or spidermonkey). anyway, just thought there might be people who would be intrigued (or horrified enough to care what's being done in the name of computer science) by either of these projects. I've added pyjamas to the implementations page on the Python Wiki in the compilers section: http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. Does this make it a 'python implementation'? That would be news to me but I've been wrong many times before. It converts Python code to Javascript. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Granularity of OSError
In MRAB writes: >If, for example, you're >going to copy a file, it's a good idea to check beforehand that there's >enough space available for the copy. How do you do that? TIA, kynn -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
Peng Yu wrote: Hi, I did a google search and found various parser in python that can be used to parse different files in various situation. I don't see a page that summarizes and compares all the available parsers in python, from simple and easy-to-use ones to complex and powerful ones. Second hit for "python parser": http://nedbatchelder.com/text/python-parsers.html -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
Daniel Fetchinson schrieb: the pyjamas project is taking a slightly different approach to achieve this same goal: beat the stuffing out of the pyjamas compiler, rather than hand-write such large sections of code in pure javascript, and double-run regression tests (once as python, second time converted to javascript under pyv8run, d8 or spidermonkey). anyway, just thought there might be people who would be intrigued (or horrified enough to care what's being done in the name of computer science) by either of these projects. I've added pyjamas to the implementations page on the Python Wiki in the compilers section: http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. Does this make it a 'python implementation'? That would be news to me but I've been wrong many times before. It is an implementation. It takes python-code, and translates that to JS - so you code in Python, but the code is executed inside a JS-"VM". Diez -- http://mail.python.org/mailman/listinfo/python-list
OK to memoize re objects?
My Python code is filled with assignments of regexp objects to
globals variables at the top level; e.g.:
_spam_re = re.compile('^(?:ham|eggs)$', re.I)
Don't like it. My Perl-pickled brain wishes that re.compile was
a memoizing method, so that I could use it anywhere, even inside
tight loops, without ever having to worry about the overhead of
regexp compilation.
Of course, I can do the memoization myself. Would it be a bad
idea? How much state does a re object keep? Or to put it differently,
what should be avoided to keep a regexp object essentially "stateless",
so that its memoization makes sense?
TIA!
kynn
--
http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
greg wrote: So in my humble opinion, the strong form of the Sapir-Whorf hypothesis is bunk. :-) It also seems not to have been their hypothesis ;-). from http://en.wikipedia.org/wiki/Sapir-Whorf_hypothesis "Since neither Sapir nor Whorf had ever stated an actual hypothesis, Lenneberg formulated one based on a condensation of the different expressions of the notion of linguistic relativity in their works. He found it necessary to formulate the hypothesis as two basic formulations which he called the "weak" and the "strong" formulation respectively: 1. Structural differences between language systems will, in general, be paralleled by nonlinguistic cognitive differences, of an unspecified sort, in the native speakers of the language. 2. The structure of anyone's native language strongly influences or fully determines the worldview he will acquire as he learns the language.[14] Since Lenneberg believed that the objective reality denotated by language was the same for speakers of all language he decided to test how different languages codified the same message differently and whether differences in codification could be proven to affect their behaviour." ..."Lenneberg's two formulations of the hypothesis became widely known and attributed to Whorf and Sapir while in fact the second formulation, verging on linguistic determinism, was never advanced by either of them." In other words, the 'Strong' form is a strawman erected by someone somewhat opposed to their ideas. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
On 19 Sep, 11:04 pm, [email protected] wrote: Daniel Fetchinson wrote: the pyjamas project is taking a slightly different approach to achieve this same goal: beat the stuffing out of the pyjamas compiler, rather than hand-write such large sections of code in pure javascript, and double-run regression tests (once as python, second time converted to javascript under pyv8run, d8 or spidermonkey). anyway, just thought there might be people who would be intrigued (or horrified enough to care what's being done in the name of computer science) by either of these projects. I've added pyjamas to the implementations page on the Python Wiki in the compilers section: http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. Does this make it a 'python implementation'? That would be news to me but I've been wrong many times before. It converts Python code to Javascript. The question is whether it converts Python code to JavaScript code with the same behavior. I think you're implying that it does, but you left it implicit, and I think the point is central to deciding if pyjamas is a Python implementation or not, so I thought I'd try to make it explicit. Does pyjamas convert any Python program into a JavaScript program with the same behavior? I don't intend to imply that it doesn't - I haven't been keeping up with pyjamas development, so I have no idea idea. I think that the case *used* to be (perhaps a year or more ago) that pyjamas only operated on a fairly limited subset of Python. If this was the case but has since changed, it might explain why some people are confused to hear pyjamas called a Python implementation now. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
[email protected] wrote: On 19 Sep, 11:04 pm, [email protected] wrote: Daniel Fetchinson wrote: the pyjamas project is taking a slightly different approach to achieve this same goal: beat the stuffing out of the pyjamas compiler, rather than hand-write such large sections of code in pure javascript, and double-run regression tests (once as python, second time converted to javascript under pyv8run, d8 or spidermonkey). anyway, just thought there might be people who would be intrigued (or horrified enough to care what's being done in the name of computer science) by either of these projects. I've added pyjamas to the implementations page on the Python Wiki in the compilers section: http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. Does this make it a 'python implementation'? That would be news to me but I've been wrong many times before. It converts Python code to Javascript. The question is whether it converts Python code to JavaScript code with the same behavior. I think you're implying that it does, but you left it implicit, and I think the point is central to deciding if pyjamas is a Python implementation or not, so I thought I'd try to make it explicit. Does pyjamas convert any Python program into a JavaScript program with the same behavior? Barring the unimplemented libraries and bugs, yes. If you read the original post in this thread, you will see that on the roadmap is running the entire Python regression suite. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: OK to memoize re objects?
kj wrote:
My Python code is filled with assignments of regexp objects to
globals variables at the top level; e.g.:
_spam_re = re.compile('^(?:ham|eggs)$', re.I)
Don't like it. My Perl-pickled brain wishes that re.compile was
a memoizing method, so that I could use it anywhere, even inside
tight loops, without ever having to worry about the overhead of
regexp compilation.
Just use re.search(), etc. They already memoize the compiled regex objects.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
On Sep 19, 2:12 am, greg wrote: > Hendrik van Rooyen wrote: > > there would be no way for a language to change > > and grow, if it were literally true that you cannot think of something that > > you have no word for. > > From my own experience, I know that it's possible for me to > think about things that I don't have a word for. An example > occured once when I was developing a 3D game engine, and > I was trying to think of a name for the thing that exists > where two convex polyhedra share a face, except that the > face is missing (it's hard to explain even using multiple > words). > > I couldn't think of any word that fully expressed the precise > concept I had in mind. Yet I was clearly capable of thinking > about it, otherwise I wouldn't have noticed that I was missing > a word! > > So in my humble opinion, the strong form of the Sapir-Whorf > hypothesis is bunk. :-) > > -- > Greg You have a good point here Greg! The break down in communication is a result of verbal language. What is verbal language? It *is* simply a way to reconstruct electrical signals from the "senders" brain to the "receivers" brain, that's it! One can easily grasp very complicated ideas (even abstract ideas) in ones mind in the flash of a nano second! However, reconstucting those same electrical signals and synapses in the mind of another human by means of *fancy* grunts-and-groans, is sometimes an exercise in asininity! You can think of natural language as exporting the state of "program" to file so "program2" can parse the file and re-create the state of "program1" within itself -- very inefficient and very, very ugly! All the "hailer's" of languages who make claims of natural language's beauty and elegance should give some real thought to the problems of human communication! Natural language is kludgy at best, and will NEVER be an elegant system! Hopefully i have help to successfully reconstruct this concept in your brain...? -- http://mail.python.org/mailman/listinfo/python-list
Re: class initialization problem
rantingrick wrote: > >WHY did i need do this you may ask? >I am creating geometry with OpenGL. When you create a face you must >specify a winding order (clockwise or counter clockwise) this winding >order controls which side of the face will be visible (since only one >side of a face is rendered). So to create a two sided face you must >create two faces that share the exact same points, BUT have opposite >windings, hence the need to create a face with a "backface" attribute >that contains the mirrored face instance. So now i can move the >frontface around and i have a handy reference to the backface so i can >make it follow! Surely it would be better to use inheritance for this. Create a class RawFace that encapsulated the points, then have a derived class Face that creates a second RawFace for the backface. No recursion problems with that. As it is, you have a somewhat confusing situation. If I do this: x = Face( points ) Now I can refer to x.backface, but there is no x.backface.backface. -- Tim Roberts, [email protected] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
>> the pyjamas project is taking a slightly different approach to achieve >> this same goal: beat the stuffing out of the pyjamas compiler, rather >> than hand-write such large sections of code in pure javascript, and >> double-run regression tests (once as python, second time converted to >> javascript under pyv8run, d8 or spidermonkey). >> >> anyway, just thought there might be people who would be intrigued (or >> horrified enough to care what's being done in the name of computer >> science) by either of these projects. > I've added pyjamas to the implementations page on the Python Wiki in > the compilers section: > > http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. Does this make it a 'python implementation'? That would be news to me but I've been wrong many times before. >>> >>> It converts Python code to Javascript. >> >> The question is whether it converts Python code to JavaScript code with >> the same behavior. I think you're implying that it does, but you left >> it implicit, and I think the point is central to deciding if pyjamas is >> a Python implementation or not, so I thought I'd try to make it explicit. >> >> Does pyjamas convert any Python program into a JavaScript program with >> the same behavior? > > Barring the unimplemented libraries and bugs, yes. If you read the original > post in this thread, you will see that on the roadmap is running the entire > Python regression suite. Okay, this is true, something I missed. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Granularity of OSError
kj wrote: In MRAB writes: If, for example, you're going to copy a file, it's a good idea to check beforehand that there's enough space available for the copy. How do you do that? There's os.statvfs(...), although that's Unix only. The point is that it's sometimes a good idea to do a cheap check first before attempting an operation that's 'expensive' even when it fails. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sep 19, 6:05 pm, Robert Kern wrote: > Peng Yu wrote: > > Hi, > > > I did a google search and found various parser in python that can be > > used to parse different files in various situation. I don't see a page > > that summarizes and compares all the available parsers in python, from > > simple and easy-to-use ones to complex and powerful ones. > > Second hit for "python parser": > > http://nedbatchelder.com/text/python-parsers.html This is more a less just a list of parsers. I would like some detailed guidelines on which one to choose for various parsing problems. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Granularity of OSError
On 2009-09-20, MRAB wrote: > kj wrote: >> In MRAB >> writes: >> >>> If, for example, you're going to copy a file, it's a good idea >>> to check beforehand that there's enough space available for >>> the copy. >> >> How do you do that? >> > There's os.statvfs(...), although that's Unix only. > > The point is that it's sometimes a good idea to do a cheap > check first before attempting an operation that's 'expensive' > even when it fails. It's also important to note than under some circumstances, the side-effects of that particular failure (filling up a disk partition) can be unpleasant -- particularly if you do it as root. Incoming Mail gets bounced/dropped, cron jobs fail, etc. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
How to change string or number passed as argument?
Hi, I know that strings or numbers are immutable when they passed as arguments to functions. But there are cases that I may want to change them in a function and propagate the effects outside the function. I could wrap them in a class, which I feel a little bit tedious. I am wondering what is the common practice for this problem. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: How to change string or number passed as argument?
I know that strings or numbers are immutable when they passed as arguments to functions. But there are cases that I may want to change them in a function and propagate the effects outside the function. I could wrap them in a class, which I feel a little bit tedious. I am wondering what is the common practice for this problem. The most common way is to simply return the altered string if you need it: def my_func(some_string): result = do_stuff(...) some_string = mutate(some_string) return result, some_string result, value = my_func(value) This gives the flexibility for the caller to decide whether they want to allow the function to mutate the parameter or not. You can also use a mutable argument: def my_func(lst): lst[0] = mutate(lst[0]) return do_stuff(...) s = ["hello"] result = my_func(s) print s[0] but this is horribly hackish. In general, mutating arguments is frowned upon because it leads to unexpected consequences. Just like I don't expect sin(x) or cos(x) to go changing my input value, python functions should behave similarly. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)
The other day I needed to convert a date like "August 2009" into a "seconds-since-epoch" value (this would be for the first day of that month, at the first second of that day). In Python, I came up with this: #!/usr/bin/env python import datetime import time time_in_sse = time.mktime( datetime.datetime(2009, 8, 1).timetuple() ) print time_in_sse I *wanted* to just use time.mktime(), but it wouldn't work unless I could specify the *complete* time tuple value (who would have all that handy?!). I also wanted to then just do datetime.datetime (...).secs_since_epoch(), but it didn't support a function like that -- not one I could find anyway. Note, to arrive at that above solution, I had to spend a fair amount of time reading the docs on both the time and datetime modules, and then wondering why the methods I wanted weren't there. Am I missing something and maybe used the wrong methods/modules here? Contrast this to Perl, where the solution I came up with in about 5 minutes was: #!/usr/bin/env perl use DateTime; my $dt = DateTime->new(year => 2009, month => 8); print $dt->epoch, "\n"; (it only took 5 minutes because the docs for DateTime tell you exactly what you want to know right at the top on the first page of the docs.) -- http://mail.python.org/mailman/listinfo/python-list
Can print() be reloaded for a user defined class?
Hi,
I have the following code. The last line does not print the members
("x" and "y") of 'my_bin'. I am wondering if there is a way to reload
the print function for bin, so that the last line print the members of
'my_bin'.
Regards,
Peng
class bin:
def __init__(self, x, y) :
self.x = x
self.y = y
if __name__ == '__main__':
my_bin = bin(1, 2)
print my_bin
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
On Sep 19, 9:28 pm, Peng Yu wrote:
> Hi,
>
> I have the following code. The last line does not print the members
> ("x" and "y") of 'my_bin'. I am wondering if there is a way to reload
> the print function for bin, so that the last line print the members of
> 'my_bin'.
>
> Regards,
> Peng
>
> class bin:
> def __init__(self, x, y) :
> self.x = x
> self.y = y
>
> if __name__ == '__main__':
>
> my_bin = bin(1, 2)
> print my_bin
use the __str__ and or __repr__ methods
> class Bin:
> def __init__(self, x, y) :
> self.x = x
> self.y = y
def __str__(self):
return 'Bin(%s, %s)' %(self.x, self.y)
__repr__ = __str__
Please use an initial capital letter when defining a class, this is
the accepted way in many languages!!!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
On Sep 19, 9:34 pm, r wrote:
> On Sep 19, 9:28 pm, Peng Yu wrote:
>
>
>
> > Hi,
>
> > I have the following code. The last line does not print the members
> > ("x" and "y") of 'my_bin'. I am wondering if there is a way to reload
> > the print function for bin, so that the last line print the members of
> > 'my_bin'.
>
> > Regards,
> > Peng
>
> > class bin:
> > def __init__(self, x, y) :
> > self.x = x
> > self.y = y
>
> > if __name__ == '__main__':
>
> > my_bin = bin(1, 2)
> > print my_bin
>
> use the __str__ and or __repr__ methods
>
> > class Bin:
> > def __init__(self, x, y) :
> > self.x = x
> > self.y = y
>
> def __str__(self):
> return 'Bin(%s, %s)' %(self.x, self.y)
> __repr__ = __str__
>
> Please use an initial capital letter when defining a class, this is
> the accepted way in many languages!!!
I want to understand the exact meaning of the last line ('__repr__ =
__str__'). Would you please point me to the section of the python
manual that describes such usage.
Regards,
Peng
--
http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
Daniel Fetchinson wrote: Barring the unimplemented libraries and bugs, yes. If you read the original post in this thread, you will see that on the roadmap is running the entire Python regression suite. No, it's getting close to running the entire Pyjamas regression suite, which is something else. Pyjamas is a dialect of Python in which many primitives have Javascript semantics. See http://code.google.com/p/pyjamas/wiki/MigrationGuide John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)
On Sep 19, 7:22 pm, Schif Schaf wrote: > The other day I needed to convert a date like "August 2009" into a > "seconds-since-epoch" value (this would be for the first day of that > month, at the first second of that day). > > In Python, I came up with this: > > > #!/usr/bin/env python > > import datetime > import time > > time_in_sse = time.mktime( > datetime.datetime(2009, 8, 1).timetuple() > ) > > print time_in_sse > > > I *wanted* to just use time.mktime(), but it wouldn't work unless I > could specify the *complete* time tuple value (who would have all that > handy?!). Was it really that hard to add a few zeros to the tuple for values you didn't know? time.mktime((2009, 8, 1, 0, 0, 0, 0, 0, -1)) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
On Sep 19, 9:53 pm, Peng Yu wrote:
(snip)
> I want to understand the exact meaning of the last line ('__repr__ =
> __str__'). Would you please point me to the section of the python
> manual that describes such usage.
simple i assined any call to __repr__ to the __str__ methods.
>>> class Test():
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return 'Test(%s, %s)' %(self.x, self.y)
>>> t = Test(1,2)
>>> t
<__main__.Test instance at 0x02CD15D0>
>>> print t
Test(1, 2)
>>> repr(t)
'<__main__.Test instance at 0x02CD15D0>'
>>> class Test():
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return 'Test(%s, %s)' %(self.x, self.y)
__repr__ = __str__
>>> t = Test(3,4)
>>> t
Test(3, 4)
>>> print t
Test(3, 4)
>>> repr(t)
'Test(3, 4)'
it's good for command line testing since you will not need to call
print < instance > all the time. You may not always want to use this
binding of __repr__ to __str__, but it has some effective uses ;)
--
http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
Dear All, Thank you for the information. I think I've some idea what the problem is about after seeing the replies. More information about my system and my script PIII 1Ghz, 512MB RAM, Windows XP SP3 The script monitors global input using PyHook, and calculates on the information collected from the events to output some numbers. Based on the numbers, the script then performs some automation using SendKeys module. here is the memory usage: firefox.exe, 69MB, 109MB svchost.exe, 26MB, 17MB pythonw.exe, 22MB, 17MB searchindexer.exe, 16MB, 19MB My first guess is that the script calculated for too long time after receiving an event before propagating it to the default handler, resulting the system to be non-responsive. I will try to implement the calculation part in another thread. Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour. On Sun, Sep 20, 2009 at 5:22 AM, Dave Angel wrote: > kakarukeys wrote: > >> Hi, >> >> When I am running a loop for a long time, calculating heavily, the CPU >> usage >> is at 100%, making the comp not so responsive. Is there a way to >> control the >> CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help >> although CPU usage level is reduced, but it's unstable. >> >> Regards, >> W.J.F. >> >> >> > Controlling a task's scheduling is most definitely OS-dependent., so you > need to say what OS you're running on. And whether it's a multi-core and or > duo processor. > > In Windows, there is a generic way to tell the system that you want to give > a boost to whatever task has the user focus (generally the top-window on the > desktop). On some versions, that's the default, on others, it's not. You > change it from Control Panel. I'd have to go look to tell you what applet, > but I don't even know if you're on Windows. > > In addition, a program can adjust its own priority, much the way the Unix > 'nice' command works. You'd use the Win32 library for that. > > And as you already tried, you can add sleep() operations to your > application. > > But if you're looking at the task list in the Windows Task Manager, you > aren't necessarily going to see what you apparently want. There's no way to > programmatically tell the system to use a certain percentage for a given > task. If there's nothing else to do, then a low priority task is still > going to get nearly 100% of the CPU. Good thing. But even if there are > other things to do, the scheduling is a complex interaction between what > kinds of work the various processes have been doing lately, how much memory > load they have, and what priority they're assigned. > > If you just want other processes to be "responsive" when they've got the > focus, you may want to make that global setting. But you may need to better > define "responsive" and "unstable." > > DaveA > -- http://mail.python.org/mailman/listinfo/python-list
urllib2, https and gzipped files
I'm trying to use urllib2 to download some gzipped files from an https server, but I cannot correctly open the file. It happens to be an mbox file -- a mailing list archive to be exact. Upon calling open, the file starts to be unzipped. Content-Length is read as the length of the first post in the archive and exactly that amount of text is downloaded and that's it. I can do this manually in a browser, but cannot do it any other way. I couldn't find a solution searching on the web, but tested wget and curl -- and both of them mess up in a similar way as my python code. curl is exactly the same. It gets the first few thousand bytes as text and stops. wget, tries a second time and downloads the remaining number of bytes to match the actual compressed file size, but the second part just looks like random bytes. The same code works on other sites with the same archive; but the difference is that they are http connections, not https. Any ideas? Barry -- http://mail.python.org/mailman/listinfo/python-list
What are the naming convention for private member variable, and private and public member function?
Hi, It says in http://www.python.org/dev/peps/pep-0008/ "Method Names and Instance Variables Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability. Use one leading underscore only for non-public methods and instance variables." I am wondering what is the different between member function and member variable in term of naming convention. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
Peng Yu wrote: > This is more a less just a list of parsers. I would like some detailed > guidelines on which one to choose for various parsing problems. > > Regards, > Peng It depends on the parsing problem. Obviously your not going to use an INI parser to work with XML, or vice versa. Likewise some formats can be parsed in different ways, XML parsers for example are often build around a SAX or DOM model. The differences between them (hit Wikipedia) can effect the performance of your application, more then learning how to use an XML parsers API can effect the hair on your head. For flat data, simple unix style rc or dos style ini file will often suffice, and writing a parser is fairly trivial; in fact writing a config file parser is an excellent learning exercise, to get a feel for a given languages standard I/O, string handling, and type conversion features. These kind of parsers tend to be pretty quick because of their simplicity, and writing a small but extremely fast one can be enjoyable at times; one of these days I need to do it in X86 assembly just for the hell of it. Python includes an INI parser in the standard library. XML serves well for hierarchical data models, but can be a royal pain to write code around the parsers (IMHO anyway!), but often is handy. Popular parsers for XML include expat and libxml2 - there is also a more "Pythonic" wrapper for libxml/libxslt called py-lxml; Python also comes with parsers for XML. Other formats such as JSON, YAML, heck even S-expressions could be used and parsed. Some programs only parse enough to slup up code and eval it (not always smart, but sometimes useful). In general the issues to consider when selecting a parser for a given format, involve: speed, size, and time. How long does it take to process the data set, how much memory (size) does it consume, and how much bloody time will it take to learn the API ;). The best way to choose a parser, is experiment with several, test (and profile!) them according to the project, then pick the one you like best, out of those that are suitable for the task. Profiling can be very important. -- TerryP -- http://mail.python.org/mailman/listinfo/python-list
How to get the minimum number that can be represented?
Hi, Suppose I want to define a function that return the minimum number that can be represented. def f(x): #body That it, if I call f(10), f will return the minimum integer that can be represented in the machine; if I cal f(10.5), f will return the minimum float that can be represented in the machine. Could somebody let me know what should be in the function body? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)
On Sep 19, 10:57 pm, Carl Banks wrote: > On Sep 19, 7:22 pm, Schif Schaf wrote: > > > I *wanted* to just use time.mktime(), but it wouldn't > > work unless I could specify the *complete* time tuple > > value (who would have all that handy?!). > > Was it really that hard to add a few zeros to the tuple > for values you didn't know? > > time.mktime((2009, 8, 1, 0, 0, 0, 0, 0, -1)) To be fair, the docs for the time module (I'm looking at the help file for 2.6.2) are written in such a way that it's not clear you can use zero for the unknown day of the week or day of the year. The passage for time.mktime(t) that states "If the input value cannot be represented as a valid time, either OverflowError or ValueError will be raised" *might* imply that your tuple is invalid, because 2009-08-01 was not a Monday and 0 is not even in the valid range for tm_yday. In my opinion, this is a deficiency of the docs. On the other hand, I think the OP, as well as users of Python in general, should probably not be so timid. Just try something and see if it works. Throw zeros in for the unknown values and maybe you'll get a ValueError (like your cautious, doc-respecting mind is expecting) or maybe the routine will actually do the appropriate and convenient thing and trust your year, month, and day. In this case, the latter is happily true. For what it's worth, it's true that the time module is not particularly Pythonic. It's mostly a wrapper for C library functions, and the docs do imply this near the top. Personally, I think the wrapper could stand to be less thin and provide friendlier access while still using the C library, but I doubt it's a big enough pain point to spur anyone to improve it. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)
On Sep 19, 7:22 pm, Schif Schaf wrote:
> The other day I needed to convert a date like "August 2009" into a
> "seconds-since-epoch" value (this would be for the first day of that
> month, at the first second of that day).
You could use Time::Piece:
[ss...@localhost ~]$ perl -lMTime::Piece -e'$t=Time::Piece->strptime
("August 2009","%b %Y"); print $t->epoch'
1249084800
--
http://mail.python.org/mailman/listinfo/python-list
Re: detmining name during an assignment
On Fri, Sep 18, 2009 at 6:57 PM, Jamie Riotto wrote:
> However, I'll have to keep looking for a more elegant solution.
> Telling a user that typing:
> cube1 = Cube(name = cube1) is a good thing because its pythonic is
> somehow unsatisfying.
That isn't pythonic. The usual pythonic way to map names to objects
is to use one of python's most used datatypes: the dictionary. So
they might do something like this:
scene["Cube1"] = Cube(xpos, ypos, zpos)
You could either have your Scene class inherit from dict, or write
custom __getattr__ and __setattr__ methods for it. Alternatively, you
could add functions to your Scene class that manipulate a dictionary
that isn't directly exposed, and your users could do something like
this:
scene.add_item("Cube1", Cube(xpos, ypos, zpos))
Where the add_item method of the Scene would keep an internal
dictionary of all of the objects in the scene.
--
Jerry
--
http://mail.python.org/mailman/listinfo/python-list
Re: What are the naming convention for private member variable, and private and public member function?
> It says in http://www.python.org/dev/peps/pep-0008/ > > "Method Names and Instance Variables > > Use the function naming rules: lowercase with words separated by > underscores as necessary to improve readability. > > Use one leading underscore only for non-public methods and > instance > variables." > > I am wondering what is the different between member function and > member variable in term of naming convention. Nothing that I know of. If they are "private" they should both start with an underscore, if they are "public" they should not. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the minimum number that can be represented?
> Suppose I want to define a function that return the minimum number > that can be represented. > > def f(x): > #body > > That it, if I call f(10), f will return the minimum integer that can > be represented in the machine; if I cal f(10.5), f will return the > minimum float that can be represented in the machine. > > Could somebody let me know what should be in the function body? I'm not sure this is what you are looking for but have a look at import sys print sys.maxint HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
John Nagle wrote: Daniel Fetchinson wrote: Barring the unimplemented libraries and bugs, yes. If you read the original post in this thread, you will see that on the roadmap is running the entire Python regression suite. No, it's getting close to running the entire Pyjamas regression suite, which is something else. I was referring to this statement: """ on the roadmap of this sub-sub-project of pyjamas is: * to throw pyv8run at the standard http://python.org regression tests and see what sticks """ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
"r" wrote in message news:[email protected]... On Sep 19, 9:53 pm, Peng Yu wrote: (snip) > I want to understand the exact meaning of the last line ('__repr__ = > __str__'). Would you please point me to the section of the python > manual that describes such usage. simple i assined any call to __repr__ to the __str__ methods. Just define __repr__. str() uses __repr__ if __str__ isn't defined. -Mark -- http://mail.python.org/mailman/listinfo/python-list
Compile kinterbasdb with mingw32 and python 2.6 - DLL load failed
This is what I did so far: #1. Install Python 2.6, Firebird 1.5 server (with libs and headers), egenix mx base and mingw C compiler #2. put "c:\MinGW\bin" on the PATH (or wherever it is) #3. extract kinterbasdb source to a temp folder #4. hack setup.cfg. Change the build section: [build] compiler=mingw32 #5. hack setup.py Replace this: customCompilerName = 'msvc' With this: customCompilerName = 'mingw32-gcc' #6. run "python setup.py install" The building and installation went find. But I cannot "import kinterbasdb" because I get a "DLL load failed" error. I figured out that has something to do with msvcr90 and "_ftime". Can you please give me some advice how to solve this problem? Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
