Re: While we're talking about annoyances
On Apr 30, 3:51 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Michael Hoffman <[EMAIL PROTECTED]> wrote: > >... > > > >> Well, counting the index() function that is called in both cases, the > > >> original rank() had one sort, but my version has two sorts. > > > > That doesn't affet the big-O behavior -- O(N log N) holds whether you > > > have one sort, or three, or twentyseven. Again we're not talking about big-O: we're talking about which one is faster. > > I've taught programming classes before, and I would have had to fail > > anybody who misunderstood speed badly enough to claim that something > > repeating an O(N log N) algorithm 27 times was no faster than doing it > > once. ;-) > > As for me, I would fail somebody who thought they could compare speed > this way -- if the O(N log N) executed 27 times took (on a given > machine) 1 millisecond times N times log N, and the other one (on the > same machine) 1 second times N times log N (and in the big-O notation > you can NEVER infer what the multiplicative constant is), for example, > such a comparison would be totally of base. Of course you are right: this is basic asymptotic analysis. You also know very well that this is not what I or Michael were thinking of. He was simply saying that repeating the *same thing* 27 times takes more time than simply doing it once, as it was made clear by my earlier post that his solution involved repeating the same index() function twice. > > As Arnaud points out, asymptotic behavior is not the same as speed. His > > original statement that the more recently proposed definitions of rank() > > are slower than the OP's may be correct. And if it's not, it's not > > because they're all O(N log N). > > And if it is, it's not because of the "one sort" versus "two sorts": by > that sole criterion you just cannot guess (sensibly) at speed (measuring > is much better, though it has its own pitfalls). I'm afraid you can draw some conclusions in this case, precisely *because* one version has one sort less than the other (that is what I was hinting at in my first post). Let's say the time complexity of the first sort is: f(n) ~ Knlogn The time complexity of the second sort is: g(n) ~ Lnlogn The time complexity of the simple loop that can replace the second sort is: h(n) ~ Hn Now because the whole algorithm consists of doing one sort THEN the second thing(sort or loop), the time complexities of the two versions are as follow: Two sort version: f(n)+g(n) ~ Knlogn+Lnlogn ~ (K+L)nlogn One sort version: f(n)+h(n) ~ Knlogn + Hn ~ Knlogn(1+H/Klogn) ~ Knlogn So the two sort version is (K+L)/K times slower than the one-sort version asymptotically. (in practice I reckon K=L so that makes it twice slower) -- Arnaud "Errare humanum est, sed perseverare diabolicum" -- http://mail.python.org/mailman/listinfo/python-list
Python+Pygame+PyopenGL all in one package?
Hi all, Is it possible to have Python+Pygame+PyOpenGL in one compact package so people can play the games released at pyweek.org . I have been having a hard time getting the whole thing on windows as well as linux (Ubuntu 7.04) . Strangely, my pleas for the same on pyopengl have gone unanswered. http://sourceforge.net/mailarchive/forum.php?thread_name=511f47f50704260036y2888db21p5cf650a7e472559b%40mail.gmail.com&forum_name=pyopengl-users as well as http://sourceforge.net/mailarchive/forum.php?thread_name=511f47f50704260243i2b05d595rc7fc0496531f5871%40mail.gmail.com&forum_name=pyopengl-users Even wikipedia doesn't know much about PyOpenGL except for the fact it is a package which allows the 3D redering using python. I'm an end-user hence would like to know from some experienced people if they see any way forward or not. Cheers ! -- http://mail.python.org/mailman/listinfo/python-list
Log-in to forums (using cookielib)?
Hi,
I need to login to a online forum, like a phpbb forum, and leave a
message there. I figured I need to use cookielib, but the documentation
of cookielib is not very clear to me.
I tried to just copy/paste all the cookies from FireFox into my
Python-program, like this:
import cookielib, urllib2, urllib
cookiejar=cookielib.CookieJar()
urlOpener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
values={'__utmb':'1234', 'mybbuser':'1234_1234', '__utmz':'1234',
'sid':'1234', '__utma':'1234'}
data=urllib.urlencode(values)
request=urllib2.Request("http://ep2.nl",data)
url=urlOpener.open(request)
page=url.read(1024000)
Can someone please tell me how I should log-in and leave a message on
the board?
--
http://mail.python.org/mailman/listinfo/python-list
playing sound in mac osx
Hi, I am a newbie to mac and python. Is there an easy way to play wav or mp3 sound file ? I used to use winsound module before switching to mac, but that only works for windows. Thanks Tooru P.S. I am using Mac OSX 10.4.8 and Python 2.5 -- http://mail.python.org/mailman/listinfo/python-list
Re: playing sound in mac osx
tooru honda schrieb: > Hi, > > I am a newbie to mac and python. > > Is there an easy way to play wav or mp3 sound file ? I used to use > winsound module before switching to mac, but that only works for windows. pygame might help. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Qustion about struct.unpack
On Apr 30, 9:41 am, Steven D'Aprano <[EMAIL PROTECTED]>
wrote:
> On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote:
> > Hi!
> > I have a really long binary file that I want to read.
> > The way I am doing it now is:
>
> > for i in xrange(N): # N is about 10,000,000
> > time = struct.unpack('=', infile.read(8))
> > # do something
> > tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32))
>
> I assume that is supposed to be infile.read()
>
> > # do something
>
> > Each loop takes about 0.2 ms in my computer, which means the whole for loop
> > takes 2000 seconds.
>
> You're reading 400 million bytes, or 400MB, in about half an hour. Whether
> that's fast or slow depends on what the "do something" lines are doing.
>
> > I would like it to run faster.
> > Do you have any suggestions?
>
> Disk I/O is slow, so don't read from files in tiny little chunks. Read a
> bunch of records into memory, then process them.
>
> # UNTESTED!
> rsize = 8 + 32 # record size
> for i in xrange(N//1000):
> buffer = infile.read(rsize*1000) # read 1000 records at once
> for j in xrange(1000): # process each record
> offset = j*rsize
> time = struct.unpack('=', buffer[offset:offset+8])
> # do something
> tdc = struct.unpack('=LiLiLiLi', buffer[offset+8:offset+rsize])
> # do something
>
> (Now I'm just waiting for somebody to tell me that file.read() already
> buffers reads...)
>
> --
> Steven D'Aprano
I think the file.read() already buffers reads... :)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Log-in to forums (using cookielib)?
En Tue, 01 May 2007 04:44:57 -0300, Olivier Oost <[EMAIL PROTECTED]> escribió: > I need to login to a online forum, like a phpbb forum, and leave a > message there. I figured I need to use cookielib, but the documentation > of cookielib is not very clear to me. > Can someone please tell me how I should log-in and leave a message on > the board? Sure. But considering that this smells like an Automatic Spamming Machine, I hope nobody will. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Log-in to forums (using cookielib)?
Gabriel Genellina wrote: > En Tue, 01 May 2007 04:44:57 -0300, Olivier Oost <[EMAIL PROTECTED]> > escribió: > >> I need to login to a online forum, like a phpbb forum, and leave a >> message there. I figured I need to use cookielib, but the >> documentation of cookielib is not very clear to me. >> Can someone please tell me how I should log-in and leave a message on >> the board? > > Sure. But considering that this smells like an Automatic Spamming > Machine, I hope nobody will. > > --Gabriel Genellina No, it's not meant as a spamming machine. I only need to post a message and then (if that's possible) lock the topic (I'm admin on the forum where I need this). The program first needs to read the topic for certain words (that's already working), and then reply that those words aren't welcome. I hope I made myself clear. -- http://mail.python.org/mailman/listinfo/python-list
Re: playing sound in mac osx
Is there really no cross-platform audio capability in the standard library? On 5/1/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > tooru honda schrieb: > > Hi, > > > > I am a newbie to mac and python. > > > > Is there an easy way to play wav or mp3 sound file ? I used to use > > winsound module before switching to mac, but that only works for windows. > > pygame might help. > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Master's Thesis Help Needed
I'll check it out. I'm running kubuntu (really, should work for any linux unless you're giving out .deb files) On 29 Apr 2007 18:53:51 -0700, RobJ <[EMAIL PROTECTED]> wrote: > Awhile ago I asked for your help in getting some ideas about setting > up an on-line course to learn how to use Python web frameworks. The > first section - Beginning Pylons is up and running and I would > appreciate your going through the course and taking my pre and post- > workshop surveys. The link to the site is: > > http://pyschool.robj.webfactional.com/ > > Thanks in advance for your help! > > Rob J > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Log-in to forums (using cookielib)?
En Tue, 01 May 2007 05:39:14 -0300, Olivier Oost <[EMAIL PROTECTED]> escribió: > Gabriel Genellina wrote: >> En Tue, 01 May 2007 04:44:57 -0300, Olivier Oost <[EMAIL PROTECTED]> >> escribió: >> >>> Can someone please tell me how I should log-in and leave a message on >>> the board? >> Sure. But considering that this smells like an Automatic Spamming >> Machine, I hope nobody will. > No, it's not meant as a spamming machine. I only need to post a message > and then (if that's possible) lock the topic (I'm admin on the forum > where I need this). The program first needs to read the topic for > certain words (that's already working), and then reply that those words > aren't welcome. I would verify that in the forum code if possible, not remotely. Anyway, the examples at the end of the cookielib section in the library reference are what you need: create an OpenerDirector using urllib2.build_opener, adding a suitable HTTPCookieProcessor handler. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Qustion about struct.unpack
En Tue, 01 May 2007 05:22:49 -0300, eC <[EMAIL PROTECTED]> escribió:
> On Apr 30, 9:41 am, Steven D'Aprano <[EMAIL PROTECTED]>
> wrote:
>> On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote:
>> > I have a really long binary file that I want to read.
>> > The way I am doing it now is:
>>
>> > for i in xrange(N): # N is about 10,000,000
>> > time = struct.unpack('=', infile.read(8))
>> > # do something
>> > tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32))
>>
>> Disk I/O is slow, so don't read from files in tiny little chunks. Read a
>> bunch of records into memory, then process them.
>>
>> # UNTESTED!
>> rsize = 8 + 32 # record size
>> for i in xrange(N//1000):
>> buffer = infile.read(rsize*1000) # read 1000 records at once
>> for j in xrange(1000): # process each record
>> offset = j*rsize
>> time = struct.unpack('=', buffer[offset:offset+8])
>> # do something
>> tdc = struct.unpack('=LiLiLiLi', buffer[offset+8:offset+rsize])
>> # do something
>>
>> (Now I'm just waiting for somebody to tell me that file.read() already
>> buffers reads...)
>
> I think the file.read() already buffers reads... :)
Now we need someone to actually measure it, to confirm the expected
behavior... Done.
--- begin code ---
import struct,timeit,os
fn = r"c:\temp\delete.me"
fsize = 100
if not os.path.isfile(fn):
f = open(fn, "wb")
f.write("\0" * fsize)
f.close()
os.system("sync")
def smallreads(fn):
rsize = 40
N = fsize // rsize
f = open(fn, "rb")
for i in xrange(N): # N is about 10,000,000
time = struct.unpack('=', f.read(8))
tdc = struct.unpack('=LiLiLiLi', f.read(32))
f.close()
def bigreads(fn):
rsize = 40
N = fsize // rsize
f = open(fn, "rb")
for i in xrange(N//1000):
buffer = f.read(rsize*1000) # read 1000 records at once
for j in xrange(1000): # process each record
offset = j*rsize
time = struct.unpack('=', buffer[offset:offset+8])
tdc = struct.unpack('=LiLiLiLi', buffer[offset+8:offset+rsize])
f.close()
print "smallreads", timeit.Timer("smallreads(fn)","from __main__ import
fn,smallreads,fsize").repeat(3,1)
print "bigreads", timeit.Timer("bigreads(fn)", "from __main__ import
fn,bigreads,fsize").repeat(3,1)
--- end code ---
Output:
smallreads [4.2534193777646663, 4.126013885559789, 4.2389176672125458]
bigreads [1.2897319939456011, 1.3076018578892405, 1.2703250635695138]
So in this sample case, reading in big chunks is about 3 times faster than
reading many tiny pieces.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: logging SMTPHandler and Authentication
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/ef8... That fairly old thread suggests that someone provide a patch, which hasn't happened. Sorry I missed that thread - your requirement is a reasonable one to be dealt with by the core. So I will look to implement this functionality soon. As it's not a bugfix I can't backport it, but you will be able to patch your version when I've made the change. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Error in python.org homepage.
Hi to all!!! I sended an email to webmaster at python dot org, but was blocked... why? In the homepage of python.org there is an error: the link that point to source distribution is not updated to Python 2.5.1. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
> Does sqlite come in a mac version? > The interface (pysqlite) is part of the python 2.5 standard library but you need to install sqlite itself separately (as far as I remember) from www.sqlite.org Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: logging SMTPHandler and Authentication
On May 1, 1:08 am, [EMAIL PROTECTED] wrote: > I'm new to Python, but I've been thrown into coding a pretty > complicated regression testing script. I need to email the log of the > daily test to the code owners. I thought I could use SMTPHandler for > this, but our email system requires authentication. I have not been > able to figure out how to log in using SMTPHandler. I found the > following post on comp.lang.python: > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/ef8... > > However, I haven't been able to translate this to anything I can use. > I've also looked at the source code for the SMTPHandler, but I don't > want to edit that. > > Has anyone else dealt with this? > > Thanks much, > James I've enhanced SMTPHandler in Python SVN (trunk) to accept a (username, password) tuple in a credentials argument to SMTPHandler.__init__(). The credentials, if specified, are used to do a login() call before the sendmail() call. Regards, Vinay -- http://mail.python.org/mailman/listinfo/python-list
Re: python TK scrollbar problem
James Stroud wrote: > > You are not binding to the Scrollbar.set() method nor are you assigning > the Scrollbar a command. You should try to emulate this: > > http://www.pythonware.com/library/tkinter/introduction/x7583-patterns.htm > > You need to also determine exactly what it is you want to scroll. You > probably don't want to scroll frame_grid as that contains your > scrollbar. Google "tkinter scrolled frame". Here is an example: > > http://mail.python.org/pipermail/python-list/2007-February/427886.html > > So, a suggestion would be to create a new frame to hold frame_grid and > yscroll and then use yscroll to scroll frame_grid. > > James entry do not have .yview and yscrollcommand. I will try to scroll frame_grid with a new frame. thanks Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-URL! - weekly Python news and links (Apr 30)
Cameron Laird: > ... but the *references* in that object are unlikely to be > meaningful on the second machine (or, in many cases, on the > original machine, if at a sufficiently later time). The marshaling of the object is responsible for persisting any contained references in a format that can be revivified on the second machine. Sometimes these are references to 'short lived' objects in the original process, in which case they should have been addrefed which will also lock the process alive. Other times they may be monikers to stable objects which can be reloaded. Neil -- http://mail.python.org/mailman/listinfo/python-list
Why are functions atomic?
Why are functions atomic? (I.e. they are not copied.) For example, I would like to make a copy of a function so I can change the default values: >>> from copy import copy >>> f = lambda x: x >>> f.func_defaults = (1,) >>> g = copy(f) >>> g.func_defaults = (2,) >>> f(),g() (2, 2) I would like the following behaviour: >>> f(),g() (1,2) I know I could use a 'functor' defining __call__ and using member variables, but this is more complicated and quite a bit slower. (I also know that I can use new.function to create a new copy, but I would like to know the rational behind the decision to make functions atomic before I shoot myself in the foot;-) Thanks, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Problems with time
I am running on an AIX system with time zone set to BST
If I run the following, I get the GMT time, i.e an hour less than the
correct time.
How can I get the correct time
now = time()
timeProcessed = strftime("%H:%M",gmtime(now))
--
http://mail.python.org/mailman/listinfo/python-list
Re: zipfile: grabbing whole directories
> The built in zipfile.write doesn't seem to like taking a directory instead > of a filename. > > for example: > for each in listofdir: > archive.write(each) > > blows up when one of the items listed in listofdir is a subdirectory. > > File "/usr/local/lib/python2.4/zipfile.py", line 405, in write > fp = open(filename, "rb") > > is there a mode or a '-r' style param I am missing? I guess what you really want is recursively archive every file in a directory and its subdirectories. If that is the case you can use os.walk to iterate over all such files so you can archive all of them while the directory structure will be preserved. HTH, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
You bottom posters really are a bunch of supercilious, self-righteous bigots. Personally, I find bottom-posting like reading a book backwards ... it doesn't work for me. And regardless of his response, Mr Bruney IS an MVP, he is clearly knowledgeable in his subject, and his book is well enough thought of to make me consider buying it. "Sherm Pendley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Juan T. Llibre" <[EMAIL PROTECTED]> writes: > >> Top or bottom posting is a user choice. > > Yes, one can choose to be polite and follow established usenet > conventions, or one can choose to be rude and self-centered. > > Those who choose rudeness over courtesy can expect to be called down > for it - which is arguably rude in itself, but on usenet one reaps what > one sows. Someone who can't deal with that, shouldn't be on usenet. > > sherm-- > > -- > Web Hosting by West Virginians, for West Virginians: http://wv-www.net > Cocoa programming in Perl: http://camelbones.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with time
loial schrieb:
> I am running on an AIX system with time zone set to BST
>
> If I run the following, I get the GMT time, i.e an hour less than the
> correct time.
>
> How can I get the correct time
>
> now = time()
>
> timeProcessed = strftime("%H:%M",gmtime(now))
>
localtime?
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: Launching an independent Python program in a cross-platform way (including mac)
My apologies about the last post; I posted my "test" code by mistake,
with hard-coded path information. Here's for future reference
something that is general and should work cross-platform.
André
def exec_external(code=None, path=None):
"""execute code in an external process
currently works under:
* Windows NT (tested)
* GNOME
* OS X
This also needs to be tested for KDE
and implemented some form of linux fallback (xterm?)
"""
if path is None:
path = os.path.join(os.path.expanduser("~"), "temp.py")
if os.name == 'nt' or sys.platform == 'darwin':
current_dir = os.getcwd()
target_dir, fname = os.path.split(path)
if code is not None:
filename = open(path, 'w')
filename.write(code)
filename.close()
if os.name == 'nt':
os.chdir(target_dir) # change dir so as to deal with paths
that
# include spaces
Popen(["cmd.exe", ('/c start python %s'%fname)])
os.chdir(current_dir)
elif sys.platform == 'darwin': # a much more general method can
be found
# in SPE, Stani's Python Editor -
Child.py
activate = 'tell application "Terminal" to activate'
script = r"cd '\''%s'\'';python '\''%s'\'';exit"%(target_dir,
fname)
do_script = r'tell application "Terminal" to do script
"%s"'%script
command = "osascript -e '%s';osascript -e '%s'"%(activate,
do_script)
os.popen(command)
elif os.name == 'posix':
try:
os.spawnlp(os.P_NOWAIT, 'gnome-terminal', 'gnome-
terminal',
'-x', 'python', '%s'%path)
except:
try: # untested
os.spawnlp(os.P_NOWAIT, 'konsole', 'konsole',
'-x', 'python', '%s'%path)
except:
raise NotImplementedError
else:
raise NotImplementedError
--
http://mail.python.org/mailman/listinfo/python-list
PyGEP: Gene Expression Programming for Python
Dear All, There's another open source GEP library released under the GNU. Its owner is Ryan O'Neil, a graduate student from George Mason University. In his words, "PyGEP is a simple library suitable for academic study of Gene Expression Programming in Python 2.5, aiming for ease of use and rapid implementation. It provides standard multigenic chromosomes; a population class using elitism and fitness scaling for selection; mutation, crossover and transposition operators; and some standard GEP functions and linkers." PyGEP is hosted at: http://code.google.com/p/pygep/ It looks really nice and a good GEP implementation and Ryan seems to be working really hard to maintain and improve it. So please go take a look and join the project. Best wishes, Candida --- Candida Ferreira, Ph.D. Founder and Director, Gepsoft http://www.gene-expression-programming.com/author.asp GEP: Mathematical Modeling by an Artificial Intelligence. 2nd Edition, Springer, 2006 http://www.gene-expression-programming.com/Books/index.asp GeneXproTools 4.0 -- Data Mining Software Join Associates and earn 10% in referral fees! http://www.gepsoft.com/ -- http://mail.python.org/mailman/listinfo/python-list
Antigen Notification: Antigen found a message matching a filter
Microsoft Antigen for Exchange found a message matching a filter. The message is currently Detected. Message: "Python_list Digest_ Vol 44_ Issue 7" Filter name: "KEYWORD= spam: graduate" Sent from: "[EMAIL PROTECTED]" Folder: "SMTP Messages\Inbound And Outbound" Location: "ITURAN/First Administrative Group/VITORIA" -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-URL! - weekly Python news and links (Apr 30)
In article <[EMAIL PROTECTED]>, Roger Upole <[EMAIL PROTECTED]> wrote: > >"Cameron Laird" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> In article <[EMAIL PROTECTED]>, >> Roger Upole <[EMAIL PROTECTED]> wrote: >>>Cameron Laird wrote: QOTW: "That is just as feasible as passing a cruise ship through a phone line." - Carsten Haese, on transporting a COM object across a network. Less vividly but more formally, as he notes, "A COM object represents a connection to a service or executable that is running on one computer. Transferring that connection to another computer is impossible." >>> >>>While this is indeed a nice turn of phrase, in substance it's incorrect. >>>You can marshal a live COM object and unmarshal it on a different >>>machine. >> . >> . >> . >> ... but the *references* in that object are unlikely to be >> meaningful on the second machine (or, in many cases, on the >> original machine, if at a sufficiently later time). > >In practice, you can marshal and unmarshal an object as complex >as Excel.Application which contains references to literally hundreds >of objects. . . . This surprises me; it's different from my experience. There's a lot I have to learn about COM and DCOM, though, so I thank you for the correction. The larger point, which you aptly reinforced, is that "Python-URL!"'s aim is not so much to teach facts as to provoke thought. We're successful when conversations like this ensue. -- http://mail.python.org/mailman/listinfo/python-list
RE: re-importing modules
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of John Nagle > Sent: Monday, April 30, 2007 7:32 PM > To: [email protected] > Subject: Re: re-importing modules > > [EMAIL PROTECTED] wrote: > > >>In addition to the warning that reload() does not recursively reload > >>modules that the reloaded module depends on, be warned that reloading a > >>module does not magically affect any functions or objects from the old > >>version that you may be holding on to. > > Maybe reloading modules should be deprecated. The semantics > are awful, and it interferes with higher-performance implementations. > I'd rather it weren't, personally. I'm using Python with a third-party application that provides an interactive prompt. Removing reload() would mean spending a good three minutes waiting for the application to restart any time I make the slightest change in a module supporting that application. --- -Bill Hamilton -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
Bob Phillips wrote: > You bottom posters really are a bunch of supercilious, self-righteous > bigots. Whatever. When reading answers to some statements normal people like first to see the statement then the response, not the other way around. Just because you're using broken tool (Outlook Express) it does not excuse you of being rude. Besides, reposting that spamming site address is idiotic by itself, regardless of top posting or not. [...] > And regardless of his response, Mr Bruney IS an MVP, he is clearly > knowledgeable in his subject, and his book is well enough thought of to make > me consider buying it. Regardless of who Mr Bruney is, this if completely offtopic on comp.lang.python, misc.writing, alt.consumers.uk-discounts.and.bargains and uk.people.consumers.ebay Just notice that you're posting to *more than one* group. Just please learn to use the damn reader! Even Outlook Express allows to set Followup-To: header and limit the polution. EOT -- http://mail.python.org/mailman/listinfo/python-list
Re: Store variable name in another variable
OK, I have it working with dictionaries. However I have another scenerio : I am reading a file containing records like the following : .. .. I need to substitute MYVARIABLE with the current value of MYVARIABLE in my python script and write the file out again. The file may contain many more lines and many substitution values on any line Assuming that MYVARIABLE is currently set to JOHN then the output would be Can this be done in Python? Amending the way the variable names are distinguished in the incoming file is possible if that would help. On 26 Apr, 22:02, Laurent Pointal <[EMAIL PROTECTED]> wrote: > Cameron Laird wrote: > > In article <[EMAIL PROTECTED]>, > > Laurent Pointal <[EMAIL PROTECTED]> wrote: > >>loial a ?it : > >>> I need to store a list ofvariablenames in a dictionary or list. I > >>> then later need to retrieve the names of the variables and get the > >>> values from the named variables. The named variables will already have > >>> been created and given a value. > > >>"Named variables will already have been created"... in what namespace ? > > >>Store a list of names -> dict/list (see tutorial) > > >>Then, > >>use namespace.name > >>or getattr(namespace,"name") > >>or locals()["name"] > >>or globals()["name"] > > > admin, I want to be sure you understand the advice you've been given. > > Yes, it is possible to "double dereference" through named variables; > > HOWEVER, it is essentially *never* advantageous to do so in application > > programming with Python (nor is it in Perl and PHP, despite what many > > senior people there teach). Use a dictionary, perhaps one with > > multi-dimensional keys. > > Yes, I understand. I just reply to OP question not searching the reason why > he wants to manage *variables* this way (he talk about dict, so I hope he > know that they can be used to map names to values). > So, this is not an advice, just technical ways related to the question as it > was written. > > And yes, personnally i use dictionnaries for such purpose. > > A+ > > Laurent.- Hide quoted text - > > - Show quoted text - -- http://mail.python.org/mailman/listinfo/python-list
Comparing bitmap images for differences?
I know it's a long shot but does anyone have any pointers to generic algorithms - or, even better, Python code - for comparing images and computing a value for the "difference" between them? What I want to do is to compare two bitmap images (taken from a webcam, so I'll likely be using PIL) and get some idea of the "difference" between them so I can tell if something in the image has changed, eg, a person has entered the field of view. I've had a look at the PIL documentation and all it really told me was how little I knew about image processing :-) and I couldn't see any recipes in the Python Cookbook that are aimed at this problem area. In a perfect world I'd love a method such as CompareImage(Img1, Img2) which would give a result of 255 if they're identical and 0 if not one pixel matches with a sliding scale inbetween but I know I'm probably asking for a lot there... Some ideas I've had is, maybe, increasing the contrast on both images (to take out variation in lighting etc), then compressing the results to get a hash value and comparing the hash, but that sounds likely to produce a lot of false positives. I note that PIL provides a histogram function for counting pixel colour values which sounds potentially useful and if no-one's got any better ideas I'll probably start working in that direction. Or, maybe, dump the bitmap data into a numpy array and do some kind of FFT on that but that feels very CPU- intensive. Those are my ideas so far but I thought it would be worth asking here first in case there are some known-good algorithms for doing this kind of thing rather than me trying to re-invent a wheel that ends up triangular... Thanks! Matthew. -- http://mail.python.org/mailman/listinfo/python-list
RE: Dict Copy & Compare
> -Original Message- > From: Steven D'Aprano > Sent: Monday, April 30, 2007 10:14 PM > To: [email protected] > Subject: RE: Dict Copy & Compare > > On Mon, 30 Apr 2007 12:50:58 -0500, Hamilton, William wrote: > > >> On quick question, how can I order a dict by the 'values' (not keys) > >> before > >> looping? Is that possible? > >> > > > > The easiest way I can think of is to create a new dict that's reversed. > > > > reverseDict = {} > > for key in dict1: > > if dict1[key] not in reverseDict: > > reverseDict[dict1[key]]=[key] > > else: > > reverseDict[dict1[key]].append(key) > > > > This gives you a dictionary that has the old dict's values as keys, and > > the old dict's keys as lists of values. You can then sort the keys of > > this dict and do what you want with it. Of course, the values in dict1 > > have to be valid dictionary keys for this to work. If they aren't, you > > may be able to get away with converting them to strings. > > > Oh man, maybe you need to re-think what you consider "easier". > > for value in dict1.itervalues() > do_something_with(value) This iterates through a list of values, with no information about the keys at all. Not particularly applicable to the OP's needs. > If you need the keys as well: > > for key, value in dict1.iteritems() > do_something_with(key, value) This iterates through values and keys, in no particular order. Still not useful. > > If you need to process the values (say, sort them) first: > > pairs = list(dict1.iteritems()) # or dict1.items() > pairs.sort() > for key, value in pairs: > do_something_with(key, value) > > I'll leave sorting by value instead of key as an exercise. Hrmm. Maybe you missed the part where the OP was asking how to sort a dict's contents by value? I'm pretty sure I quoted it. My bit of code would be better if I had used iteritems() (I hadn't come across that function yet). But, it's a solution, and more useful than vague statements about what someone else needs to rethink and various bits of code that don't solve the problem presented. --- -Bill Hamilton -- http://mail.python.org/mailman/listinfo/python-list
Re: Store variable name in another variable
On May 1, 6:43 am, loial <[EMAIL PROTECTED]> wrote:
> OK, I have it working with dictionaries.
>
> However I have another scenerio :
>
> I am reading a file containing records like the following :
>
>
>
>
> ..
> ..
>
> I need to substitute MYVARIABLE with the current value of MYVARIABLE
> in my python script and write the file out again.
>
> The file may contain many more lines and many substitution values on
> any line
>
> Assuming that MYVARIABLE is currently set to JOHN then the output
> would be
>
>
>
>
>
> Can this be done in Python?
s = "hello world, goodbye world"
result = s.replace("world", "moon")
print result
--
http://mail.python.org/mailman/listinfo/python-list
Re: Want to build a binary header block
Bob Greschke wrote:
> This is the idea
>
>Block = pack("240s", "")
>Block[0:4] = pack(">H", W)
>Block[4:8] = pack(">H", X)
>Block[8:12] = pack(">B", Y)
>Block[12:16] = pack(">H", Z))
>
> but, of course, Block, a str, can't be sliced. The real use of this is a
> bit more complicated such that I can't just fill in all of the "fields"
> within Block in one giant pack(). I need to build it on the fly. For
> example the pack(">H", X) may be completely skipped some times through the
> function. There are many more fields in Block than in this example and they
> are all kinds of types not just H's and B's. What I really want is a C
> struct union. :)
>
> How would I do this?
>
> Thanks!
>
> Bob
>
>
When I have something like this I normally write a class
for it and make its __str__ method return the packed output.
Example (not tested, but you should get the drift):
import struct
class blockStruct:
def __init__(self):
self.hstring=240*" "
self.W=None
self.X=None
self.Y=None
self.Z=None
return
def __str__(self):
rtnvals=[]
rtnvals.append(struct.pack("240s", self.hstring)
rtnvals.append(struct.pack(">H", W))
.
.
.
return ''.join(rtnvals)
Then in your main program
bS=blockStruct()
bs.hstring='this is a test'.ljust(240, ' ')
bs.W=12
bs.X=17
bs.Y=1
bs.Z=0
print bS
Seemed to be a good way that made debugging and understanding
easy for me.
-Larry
--
http://mail.python.org/mailman/listinfo/python-list
Antigen Notification: Antigen found a message matching a filter
Microsoft Antigen for Exchange found a message matching a filter. The message is currently Detected. Message: "Python_list Digest_ Vol 44_ Issue 8" Filter name: "KEYWORD= spam: graduate" Sent from: "[EMAIL PROTECTED]" Folder: "SMTP Messages\Inbound And Outbound" Location: "ITURAN/First Administrative Group/VITORIA" -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
Michael wrote: > Why are functions atomic? (I.e. they are not copied.) > > For example, I would like to make a copy of a function so I can change > the default values: > from copy import copy f = lambda x: x f.func_defaults = (1,) g = copy(f) g.func_defaults = (2,) f(),g() > (2, 2) > > I would like the following behaviour: > f(),g() > (1,2) > > I know I could use a 'functor' defining __call__ and using member > variables, but this is more complicated and quite a bit slower. (I > also know that I can use new.function to create a new copy, but I > would like to know the rational behind the decision to make functions > atomic before I shoot myself in the foot;-) > > Thanks, > Michael. This dont make functions copiable but may resolve your default arguments problem. Under Python 2.5, see functools.partial(). http://docs.python.org/lib/partial-objects.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
Laurent Pointal wrote: > http://docs.python.org/lib/partial-objects.html OOps http://docs.python.org/lib/module-functools.html -- http://mail.python.org/mailman/listinfo/python-list
scaling
hi, IDL language contains a function called BYTSCL to scale all values of Array that lie in the range (Min £ x £ Max) into the range (0 £ x £ Top). Is there a similar function available in python? I need this to scale the pixel values of an image using PIL. thanks in advance for any help AGK -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
On May 1, 5:06 am, Michael <[EMAIL PROTECTED]> wrote: > Why are functions atomic? (I.e. they are not copied.) > > For example, I would like to make a copy of a function so I can change > the default values: > > >>> from copy import copy > >>> f = lambda x: x > >>> f.func_defaults = (1,) > >>> g = copy(f) > >>> g.func_defaults = (2,) > >>> f(),g() > > (2, 2) > > I would like the following behaviour: > > >>> f(),g() > > (1,2) > > I know I could use a 'functor' defining __call__ and using member > variables, but this is more complicated and quite a bit slower. (I > also know that I can use new.function to create a new copy, but I > would like to know the rational behind the decision to make functions > atomic before I shoot myself in the foot;-) > > Thanks, > Michael. Does deepcopy work? -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing bitmap images for differences?
[EMAIL PROTECTED] schrieb: > I know it's a long shot but does anyone have any pointers to generic > algorithms - or, even better, Python code - for comparing images and > computing a value for the "difference" between them? > > What I want to do is to compare two bitmap images (taken from a > webcam, so I'll likely be using PIL) and get some idea of the > "difference" between them so I can tell if something in the image has > changed, eg, a person has entered the field of view. I've had a look > at the PIL documentation and all it really told me was how little I > knew about image processing :-) and I couldn't see any recipes in the > Python Cookbook that are aimed at this problem area. In a perfect > world I'd love a method such as CompareImage(Img1, Img2) which would > give a result of 255 if they're identical and 0 if not one pixel > matches with a sliding scale inbetween but I know I'm probably asking > for a lot there... > > Some ideas I've had is, maybe, increasing the contrast on both images > (to take out variation in lighting etc), then compressing the results > to get a hash value and comparing the hash, but that sounds likely to > produce a lot of false positives. I note that PIL provides a > histogram function for counting pixel colour values which sounds > potentially useful and if no-one's got any better ideas I'll probably > start working in that direction. Or, maybe, dump the bitmap data into > a numpy array and do some kind of FFT on that but that feels very CPU- > intensive. > > Those are my ideas so far but I thought it would be worth asking here > first in case there are some known-good algorithms for doing this kind > of thing rather than me trying to re-invent a wheel that ends up > triangular... There is the excellent OpenCV-library from intel which is FOSS and has a python-binding. Either using swig, or a ctypes-version: http://wwwx.cs.unc.edu/~gb/wp/blog/2007/02/04/python-opencv-wrapper-using-ctypes/ With that, you can approach your problem. What is usually done is that a sequence of background images is sampled & an average is built. Then the actual image is subtracted from that image, with an epsilon to account for noise. The result is then converted to a binary image for further processing. There are some blob-detection-recipes out there. Another approach is to use the motion-detection parts of the lib. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Store variable name in another variable
loial schrieb: > OK, I have it working with dictionaries. > > However I have another scenerio : > > I am reading a file containing records like the following : > > > > > .. > .. > > > I need to substitute MYVARIABLE with the current value of MYVARIABLE > in my python script and write the file out again. > > The file may contain many more lines and many substitution values on > any line > > Assuming that MYVARIABLE is currently set to JOHN then the output > would be > > > > > > Can this be done in Python? Amending the way the variable names are > distinguished in the incoming file is possible if that would help. There are many ways to do so in python. You can use the built-in string interpolation: "" % dict(name=value) Or you can use one of the many available templating engines, like KID, genshi, cheetah and so on. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
I am not going to join the argument, except to say that as you can see, I top post. In outlook express, you can see the messages as a thread, so you read the initial message, come to the reply and you read the response without having to scroll. Bottom posting would be fine if the previous message that promted the response was removed from the server, but it isn't, therefore, top posting is very logical. -- Best regards, Dave Colliver. http://www.AshfieldFOCUS.com ~~ http://www.FOCUSPortals.com - Local franchises available "Sebastian Kaliszewski" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Bob Phillips wrote: >> You bottom posters really are a bunch of supercilious, self-righteous >> bigots. > > Whatever. When reading answers to some statements normal people like first > to see the statement then the response, not the other way around. Just > because you're using broken tool (Outlook Express) it does not excuse you > of being rude. > > Besides, reposting that spamming site address is idiotic by itself, > regardless of top posting or not. > > [...] >> And regardless of his response, Mr Bruney IS an MVP, he is clearly >> knowledgeable in his subject, and his book is well enough thought of to >> make me consider buying it. > > > Regardless of who Mr Bruney is, this if completely offtopic on > comp.lang.python, misc.writing, alt.consumers.uk-discounts.and.bargains > and uk.people.consumers.ebay > > Just notice that you're posting to *more than one* group. Just please > learn to use the damn reader! Even Outlook Express allows to set > Followup-To: header and limit the polution. > EOT -- http://mail.python.org/mailman/listinfo/python-list
Re: re-importing modules
John Nagle wrote: > Steven D'Aprano wrote: > > I'd hate for reload to disappear, it is great for interactive > > development/debugging, at least under some circumstances. (If you have > > complex and tangled class hierarchies, it might not be powerful enough.) > > > > As for the semantics being awful, I disagree. reload() does exactly > > what it claims to do, no more, no less. > > It's more complicated than that. See > >http://arcknowledge.com/lang.jython.user/2006-01/msg00017.html > > Exactly what reloading should do is still an open question for some of > the hard cases. > > "reload" as a debug facility is fine. > Trouble comes from production programs which use it as a > reinitialization facility. I tend to agree with this; our servers do graceful restarts to pick up code changes (which, in addition to avoiding reload also means that it's easier as an admin to control the view of the code than in "automatically pick up new changes" models--in particular, you can wait until all changes are there, send SIGUSR1, and pick up the whole set of changes atomically). > Reloading a module with multiple threads running gets > complicated. It works in CPython because CPython doesn't have > real concurrency. Point of clarity: the CPython interpreter is not concurrent. Concurrency != multithreading, and multiprocess solutions run fine in CPython. -- http://mail.python.org/mailman/listinfo/python-list
Re: Restricting the alphabet of a string
Thanks, I might just move my trinary string (if I get that far) to be encoded as 0, 1, 2, thanks for your help. On 30 Apr 2007 11:14:10 -0700, John Machin <[EMAIL PROTECTED]> wrote: > On Apr 30, 9:53 pm, "Nathan Harmston" <[EMAIL PROTECTED]> > wrote: > > Hi, > > > > I ve being thinking about playing around with bit strings but use in > > some encoding problems I m considering and was trying to decide how to > > implement a bit string class. Is there a library out there for doing > > basic things with bit strings already is my first question? > > > > I know that I can extend string to bit string, but is there anyway I > > can force the alphabet to be restricted to 1's and 0's (or even 1, 0 > > and -1, as an extension to from trinary strings). > > > > class Binary_String(String): > > pass > > > > See if you can pick which line below is impractically different to the > others: > > binary: 0, 1 > "trinary": -1, 0, 1 > octal: 0, 1, 2, 3, 4, 5, 6, 7 > decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 > > HTH, > John > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
7stud <[EMAIL PROTECTED]> wrote: > Does deepcopy work? It doesn't copy a function. The easiest way to make a modified copy of a function is to use the 'new' module. >>> def f(x=2): print "x=", x >>> g = new.function(f.func_code, f.func_globals, 'g', (3,), f.func_closure) >>> g() x= 3 >>> f() x= 2 -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
On 1 May 2007 15:17:48 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: > 7stud <[EMAIL PROTECTED]> wrote: > > > Does deepcopy work? > > It doesn't copy a function. > > The easiest way to make a modified copy of a function is to use the 'new' > module. > > >>> def f(x=2): print "x=", x > > >>> g = new.function(f.func_code, f.func_globals, 'g', (3,), > f.func_closure) > >>> g() > x= 3 > >>> f() > x= 2 > -- > http://mail.python.org/mailman/listinfo/python-list > The copy module considers functions to be immutable and just returns the object. This seems pretty clearly wrong to me - functions are clearly not immutable and it's easy to copy a function using new, as shown above. >From copy.py: def _copy_immutable(x): return x for t in (type(None), int, long, float, bool, str, tuple, frozenset, type, xrange, types.ClassType, types.BuiltinFunctionType, types.FunctionType): d[t] = _copy_immutable -- http://mail.python.org/mailman/listinfo/python-list
Antigen Notification: Antigen found a message matching a filter
Microsoft Antigen for Exchange found a message matching a filter. The message is currently Detected. Message: "Python_list Digest_ Vol 44_ Issue 9" Filter name: "KEYWORD= spam: graduate" Sent from: "[EMAIL PROTECTED]" Folder: "SMTP Messages\Inbound And Outbound" Location: "ITURAN/First Administrative Group/VITORIA" -- http://mail.python.org/mailman/listinfo/python-list
Re: Qustion about struct.unpack
Wow, thank you all!
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> En Tue, 01 May 2007 05:22:49 -0300, eC <[EMAIL PROTECTED]> escribió:
>
>> On Apr 30, 9:41 am, Steven D'Aprano <[EMAIL PROTECTED]>
>> wrote:
>>> On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote:
>
>>> > I have a really long binary file that I want to read.
>>> > The way I am doing it now is:
>>>
>>> > for i in xrange(N): # N is about 10,000,000
>>> > time = struct.unpack('=', infile.read(8))
>>> > # do something
>>> > tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32))
>>>
>>> Disk I/O is slow, so don't read from files in tiny little chunks. Read a
>>> bunch of records into memory, then process them.
>>>
>>> # UNTESTED!
>>> rsize = 8 + 32 # record size
>>> for i in xrange(N//1000):
>>> buffer = infile.read(rsize*1000) # read 1000 records at once
>>> for j in xrange(1000): # process each record
>>> offset = j*rsize
>>> time = struct.unpack('=', buffer[offset:offset+8])
>>> # do something
>>> tdc = struct.unpack('=LiLiLiLi', buffer[offset+8:offset+rsize])
>>> # do something
>>>
>>> (Now I'm just waiting for somebody to tell me that file.read() already
>>> buffers reads...)
>>
>> I think the file.read() already buffers reads... :)
>
> Now we need someone to actually measure it, to confirm the expected
> behavior... Done.
>
> --- begin code ---
> import struct,timeit,os
>
> fn = r"c:\temp\delete.me"
> fsize = 100
> if not os.path.isfile(fn):
> f = open(fn, "wb")
> f.write("\0" * fsize)
> f.close()
> os.system("sync")
>
> def smallreads(fn):
> rsize = 40
> N = fsize // rsize
> f = open(fn, "rb")
> for i in xrange(N): # N is about 10,000,000
> time = struct.unpack('=', f.read(8))
> tdc = struct.unpack('=LiLiLiLi', f.read(32))
> f.close()
>
>
> def bigreads(fn):
> rsize = 40
> N = fsize // rsize
> f = open(fn, "rb")
> for i in xrange(N//1000):
> buffer = f.read(rsize*1000) # read 1000 records at once
> for j in xrange(1000): # process each record
> offset = j*rsize
> time = struct.unpack('=', buffer[offset:offset+8])
> tdc = struct.unpack('=LiLiLiLi', buffer[offset+8:offset+rsize])
> f.close()
>
> print "smallreads", timeit.Timer("smallreads(fn)","from __main__ import
> fn,smallreads,fsize").repeat(3,1)
> print "bigreads", timeit.Timer("bigreads(fn)", "from __main__ import
> fn,bigreads,fsize").repeat(3,1)
> --- end code ---
>
> Output:
> smallreads [4.2534193777646663, 4.126013885559789, 4.2389176672125458]
> bigreads [1.2897319939456011, 1.3076018578892405, 1.2703250635695138]
>
> So in this sample case, reading in big chunks is about 3 times faster than
> reading many tiny pieces.
>
> --
> Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: re-importing modules
On 5/1/07, John Nagle <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > I'd hate for reload to disappear, it is great for interactive > > development/debugging, at least under some circumstances. (If you have > > complex and tangled class hierarchies, it might not be powerful enough.) > > > > As for the semantics being awful, I disagree. reload() does exactly > > what it claims to do, no more, no less. > > It's more complicated than that. See > >http://arcknowledge.com/lang.jython.user/2006-01/msg00017.html > > Exactly what reloading should do is still an open question for some of > the hard cases. > > "reload" as a debug facility is fine. > Trouble comes from production programs which use it as a > reinitialization facility. > > Reloading a module with multiple threads running gets > complicated. It works in CPython because CPython doesn't have > real concurrency. Insisting that it work like CPython implies > an inefficient locking model. > > John Nagle > -- Not really. The problem is when people attempt to overload the current, existing reload() semantics (which are sensible and simple once you understand that they don't attempt magic, although people tend to expect the magic and they're non-intuitive in that manner). There shouldn't be any problem implementing reload() in anything that implements import. The problem is with the fancier, magical imports that people keep expecting reload() to be, and thats what both the links you've provided are attempting to write. There's potentially a place for that sort of reload(), but it clearly can't have the semantics that the current reload does, and it suffers from all the same problems that hotpatching systems always have - that it's not always clear how they should work or what they should do, and you need a very tight specification of how they will work in all the corner cases, including threading. But that's got nothing to do with the current reload(), which is simple, straightforward, and easily implemented. The GIL isn't important in this respect - there's nothing complicated about reload() that isn't also complicated about import. You either have thread-local modules (which is probably stupid, because it can result in all sorts of crazy behavior if you pass objects defined in different versions of the same module between threads) or you serialize import and access to sys.modules (or whatever your underlying implementation of the module cache is). -- http://mail.python.org/mailman/listinfo/python-list
Lisp-like macros in Python?
Hello
The Lisp crowd always brags about their magical macros. I was
wondering if it is possible to emulate some of the functionality in
Python using a function decorator that evals Python code in the stack
frame of the caller. The macro would then return a Python expression
as a string. Granted, I know more Python than Lisp, so it may not work
exactly as you expect.
Any comments and improvements are appreciated.
Regards,
Sturla Molden
__codestore__ = {}
def macro(func):
"""
Lisp-like macros in Python
(C) 2007 Sturla Molden
@macro decorates a function which must return a Python
expression
as a string. The expression will be evaluated in the context
(stack frame)
of the caller.
"""
def macro_decorator(*args,**kwargs):
global __codestore__
import sys
pycode = '(' + func(*args,**kwargs) + ')'
try:
ccode = __codestore__[pycode]
except:
ccode = compile(pycode,'macrostore','eval')
__codestore__[pycode] = ccode
frame = sys._getframe().f_back
try:
retval = eval(ccode,frame.f_globals,frame.f_locals)
return retval
except:
raise
macro_decorator.__doc__ = func.__doc__
return macro_decorator
# Usage example
def factorial(x):
""" computes the factorial function using macro expansion """
@macro
def fmacro(n):
""" returns '1' or 'x*(x-1)*(x-2)*...*(x-(x-1))' """
if n == 0:
code = '1'
else:
code = 'x'
for x in xrange(1,n):
code += '*(x-%d)' % (x)
return code
return fmacro(x)
--
http://mail.python.org/mailman/listinfo/python-list
SWIG, STL & pickle
hello, i have the following problem/question: i have a c++ class i would like to wrap using swig, easy so far. i want to be able to pickle it as well and i understand that i need to implement the setstate and getstate methods to be able to do that. now the tricky part - my c++ class uses stl vectors (and possibly other stl containers). swig can handle that, except for the pickling. what should i do to be able to pickle the whole c++ object? i am not sure i would be able to dig into stl code and implement serialization for it by hand. thanks for any help. -- http://mail.python.org/mailman/listinfo/python-list
SilverLight, a new way for Python?
Hi!
SilverLight ("MS flash killer"), is a plug-in for InternetExplorer
(Win), FireFox (Win), and Safari (Mac).
The release 1.1-Alpha come with JScript & Python (or ironPython?)
See :
http://www.microsoft.com/silverlight/default.aspx
http://www.microsoft.com/silverlight/why-compelling.aspx
http://silverlight.net/Default.aspx
http://www.microsoft.com/silverlight/install.aspx
Perhaps SilverLight is a new substitute for Python-Active-Scripting in
IE.
Perhaps SilverLight is the begin for new GUI style (vectors + XAML).
Perhaps SilverLight is the start for a new IDE (plug-in for VS-2005 or
Expression are availables).
But, I don't had try SilverLight...
Who had try it?
--
@-salutations
Michel Claveau
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
Michael wrote: > Why are functions atomic? (I.e. they are not copied.) Because Python has objects for when you need to associate state with a function. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Having problems accepting parameters to a function
Hi Experts!!
I am trying to get the following little snippet to push my data to the
function func(). What I would expect to happen is it to print out the
contents of a and loglevel. But it's not working. Can someone please
help me out.
---
#!/usr/bin/env python
import random
def func(*args, **kwargs):
print kwargs.get('a', "NOPE")
print kwargs.get('loglevel', "NO WAY")
def main():
b = []
for x in range(5):
b.append({'a':random.random(), "loglevel":10})
for y in b:
apply(func,y)
# First attempt - didn't work
# for y in b:
# func(y)
if __name__ == '__main__':
main()
--
http://mail.python.org/mailman/listinfo/python-list
Re: Having problems accepting parameters to a function
rh0dium schrieb:
> Hi Experts!!
>
> I am trying to get the following little snippet to push my data to the
> function func(). What I would expect to happen is it to print out the
> contents of a and loglevel. But it's not working. Can someone please
> help me out.
>
> ---
> #!/usr/bin/env python
>
> import random
>
> def func(*args, **kwargs):
>print kwargs.get('a', "NOPE")
>print kwargs.get('loglevel', "NO WAY")
>
> def main():
>b = []
>for x in range(5):
> b.append({'a':random.random(), "loglevel":10})
>
>for y in b:
> apply(func,y)
>
> # First attempt - didn't work
> # for y in b:
> # func(y)
>
> if __name__ == '__main__':
>main()
>
``apply()`` is deprecated -- use the asterisk-syntax_ instead.
dic = {'a': 5, 'loglevel': 10}
>>> def foo(*args, **kwargs):
... print kwargs
...
>>> foo(**dic)
{'a': 5, 'loglevel': 10}
So, your first attempt was close -- just two signs missing. :-)
HTH,
Stargaming
.. _asterisk-sytax:
http://docs.python.org/tut/node6.html#SECTION00674
--
http://mail.python.org/mailman/listinfo/python-list
Antigen Notification: Antigen found a message matching a filter
Microsoft Antigen for Exchange found a message matching a filter. The message is currently Detected. Message: "Python_list Digest_ Vol 44_ Issue 10" Filter name: "KEYWORD= spam: graduate" Sent from: "[EMAIL PROTECTED]" Folder: "SMTP Messages\Inbound And Outbound" Location: "ITURAN/First Administrative Group/VITORIA" -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems accepting parameters to a function
On May 1, 10:38 am, rh0dium <[EMAIL PROTECTED]> wrote:
> Hi Experts!!
>
> I am trying to get the following little snippet to push my data to the
> function func(). What I would expect to happen is it to print out the
> contents of a and loglevel. But it's not working. Can someone please
> help me out.
>
> ---
> #!/usr/bin/env python
>
> import random
>
> def func(*args, **kwargs):
>print kwargs.get('a', "NOPE")
>print kwargs.get('loglevel', "NO WAY")
>
> def main():
>b = []
>for x in range(5):
> b.append({'a':random.random(), "loglevel":10})
>
>for y in b:
> apply(func,y)
>
> # First attempt - didn't work
> # for y in b:
> # func(y)
>
> if __name__ == '__main__':
>main()
1) apply() is deprecated
2) You need to unpack the dictionary using ** before sending it to
func(), whereupon it will be repacked into a dictionary.
import random
def func(*args, **kwargs):
print kwargs.get('a', "NOPE")
print kwargs.get('loglevel', "NO WAY")
def main():
b = []
for x in range(5):
b.append({'a':random.random(), "loglevel":10})
for y in b:
func(**y)
if __name__ == '__main__':
main()
You might consider redefining func() so that you don't have to do the
unpack--repack:
--
http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
On May 1, 4:08 am, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote: > > Does sqlite come in a mac version? > > The interface (pysqlite) is part of the python 2.5 standard library > but you need to install sqlite itself separately (as far as I > remember) fromwww.sqlite.org > > Daniel I'm using python 2.4.4 because the download said there were more mac modules available for 2.4.4. than 2.5, and I can't seem to locate a place to download sqlite for mac. -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems accepting parameters to a function
On May 1, 11:06 am, 7stud <[EMAIL PROTECTED]> wrote: > > You might consider redefining func() so that you don't have to do the > unpack--repack... When you define a function like this: def func(**keywordargs): print keywordargs the function expects to receive arguments in the form: func(a="hello", b="world") not: func(adict) -- http://mail.python.org/mailman/listinfo/python-list
Re: SilverLight, a new way for Python?
Michel Claveau <[EMAIL PROTECTED]> wrote:
> Hi!
>
> SilverLight ("MS flash killer"), is a plug-in for InternetExplorer
> (Win), FireFox (Win), and Safari (Mac).
> The release 1.1-Alpha come with JScript & Python (or ironPython?)
IronPython.
> Perhaps SilverLight is a new substitute for Python-Active-Scripting in
> IE.
It can do much more than active scripting.
>
> But, I don't had try SilverLight...
Have you at least run the demos? To run the demos you just need Windows
or a Mac (or a virtual machine running windows) and install the
Silverlight 1.1 alpha.
>
> Who had try it?
>
There are some nice demos at
http://silverlight.net/themes/silverlight/community/gallerydetail.aspx?cat=2
In particular the DLRconsole
(http://silverlight.net/Samples/1.1/DLR-Console/python/index.htm) gives
you an interactive prompt to play with IronPython (or JScript) and XAML.
The big drawback is that despite being trumpeted as cross-platform it
runs on Windows and Mac but not Linux. The technology looks very
tempting, so much so that I can see a lot of people are going to use it.
I balked at downloading the full 5.6Gb Visual Studio beta, but once you
have the plugin installed in your browser you can run IronPython + xaml
directly from your local disc (or a web server). e.g. Download the
PhotoViewer demo and unzip and you can then immediately start hacking
the Python file. I haven't tried running it from an Apache server yet
but there since the code is just client-side it should all work (although
until it gets out of Alpha you can't actually use it for anything real).
--
http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
On May 1, 1:12 pm, 7stud <[EMAIL PROTECTED]> wrote: > I'm using python 2.4.4 because the download said there were more mac > modules available for 2.4.4. than 2.5, and I can't seem to locate a > place to download sqlite for mac. I it comes on OS X Tiger, and possibly earlier versions as well (it's used as an index for Mail.app).. You just need to download and install the pysqlite libraries. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
On May 1, 10:12 am, 7stud <[EMAIL PROTECTED]> wrote: > On May 1, 4:08 am, "Daniel Nogradi" <[EMAIL PROTECTED]> wrote: > > > > Does sqlite come in a mac version? > > > The interface (pysqlite) is part of the python 2.5 standard library > > but you need to install sqlite itself separately (as far as I > > remember) fromwww.sqlite.org > > > Daniel > > I'm using python 2.4.4 because the download said there were more mac > modules available for 2.4.4. than 2.5, and I can't seem to locate a > place to download sqlite for mac. Did you install Xcode on your Mac? If so then you should have access to a C compiler allowing you to compile sqlite from source: http://sqlite.org/download.html I checked fink (finkproject.org) but that web site shows no binary distributions for sqlite3: http://pdb.finkproject.org/pdb/package.php/sqlite3 -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
On May 1, 2007, at 12:39 PM, kirkjobsluder wrote: > On May 1, 1:12 pm, 7stud <[EMAIL PROTECTED]> wrote: >> I'm using python 2.4.4 because the download said there were more mac >> modules available for 2.4.4. than 2.5, and I can't seem to locate a >> place to download sqlite for mac. > > I it comes on OS X Tiger, and possibly earlier versions as well (it's > used as an index for Mail.app).. You just need to download and > install the pysqlite libraries. The system sqlite btw (which reports itself as version 3.1.3), is not the same as what is included in Python 2.5. Will somebody please say what version of sqlite is supported by Python 2.5? -- http://mail.python.org/mailman/listinfo/python-list
Problem with inspect.getfile
Hello, I am trying to use someone else's module that makes use of inspect.getsourcelines. The code was not working for me, so I have been debugging to see why it is not working. I have reduced my problem to getting the wrong file path in the getfile->return object.co_filename call. Basically the path I get is: "/Users/elventear/Documents/UTMEM/Projects/geotools/parsers/parser.py" When the correct path should be: "/Users/elventear/Documents/UTMEM/Projects/packages/geotools/parsers/ parser.py" Finally my PYTHONPATH contains: "/Users/elventear/Documents/UTMEM/Projects/packages" So basically, I am able to resolve correctly the package from withing Python, I don't know why there is this confusion about the filename that contains my objects and methods. Any ideas on how to correct this would be appreciated. This is under MacOSX 10.4.9, Python 2.5 (Build from Fink). Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Lisp-like macros in Python?
On May 1, 5:10 pm, sturlamolden <[EMAIL PROTECTED]> wrote: > Hello > > The Lisp crowd always brags about their magical macros. I was > wondering if it is possible to emulate some of the functionality in > Python using a function decorator that evals Python code in the stack > frame of the caller. The macro would then return a Python expression > as a string. Granted, I know more Python than Lisp, so it may not work > exactly as you expect. The 'magical macros' of lisp are executed at compile time, allowing arbitrary code transformations without the loss of run time efficiency. If you want to hack this together in python you should write a preprocessor that allows python code *to be run in future* inter spaced with python code *to be executed immediately* and replaces the executed code with it's output. The immediately executed code should be able to make use of any existing code or definitions that are marked as to be compiled in the future. This is should be quite do-able in python(I think I haven't really looked at it) because it has a REPL and everything that implies, but you'd have to implement lispy macros as some kind of def_with_macros which immediately produces a string which is equivalent to the macro expanded function definition and then evaluates it. Good luck in doing anything useful with these macros in a language with non-uniform syntax however. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
> >> I'm using python 2.4.4 because the download said there were more mac > >> modules available for 2.4.4. than 2.5, and I can't seem to locate a > >> place to download sqlite for mac. > > > > I it comes on OS X Tiger, and possibly earlier versions as well (it's > > used as an index for Mail.app).. You just need to download and > > install the pysqlite libraries. > > The system sqlite btw (which reports itself as version 3.1.3), is not > the same as what is included in Python 2.5. Will somebody please > say what version of sqlite is supported by Python 2.5 I'm using sqlite 3.3.11 with python 2.5 (on linux) but I guess some earlier versions will also work. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
> > > Does sqlite come in a mac version? > > > > The interface (pysqlite) is part of the python 2.5 standard library > > but you need to install sqlite itself separately (as far as I > > remember) fromwww.sqlite.org > > > > Daniel > > I'm using python 2.4.4 because the download said there were more mac > modules available for 2.4.4. than 2.5, and I can't seem to locate a > place to download sqlite for mac. If you use python 2.4.4 you can install the pysqlite module from http://www.initd.org/tracker/pysqlite/wiki/pysqlite (this is the interface that is included in python 2.5, you need to install sqlite itself, probably from source, with any python version). Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
David wrote: > I am not going to join the argument, except you have except to say that as you can see, I > top post. In outlook express, you can see the messages as a thread, so you > read the initial message, come to the reply and you read the response > without having to scroll. Bottom posting would be fine if the previous > message that promted the response was removed from the server, but it isn't, > therefore, top posting is very logical. > only of you top post its logical as we all don't top post its not A bird Q name an animal that fly's see top posting is illogical -- http://mail.python.org/mailman/listinfo/python-list
Re: Lisp-like macros in Python?
Converge is a Python-style language with a macro facility. See http://convergepl.org/ Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing bitmap images for differences?
> Those are my ideas so far but I thought it would be worth asking here > first in case there are some known-good algorithms for doing this kind > of thing rather than me trying to re-invent a wheel that ends up > triangular... > > Thanks! > Matthew. > This might get you started. http://tinyurl.com/7qexl Louis -- http://mail.python.org/mailman/listinfo/python-list
Grabbing the output of a long-winded shell call (in GNU/Linux)
Hello,
Suppose I want to run from within a Python GUI app some long-output
shell call. For example, from within Python I might want to call
g++ foo.cpp
I already know there are many ways to do this, e.g.,
commands.getstatusoutput('g++ foo.cpp') to name one.
The problem is that this might generate a ton of output (e.g.,
because of compilation errors), and might take a while to do so. In my
GUI, I'd like to print out the output as it's being generated, not wait
until all is done (as commands.getstatusoutput will do) and dump it at
once.
So my question is if there's a way to "grab" the output as it's being
generated. It doesn't matter if the solution is blocking (as opposed to
callback based), since threads can handle this. I just don't know how to
"grab" the output. I appreciate your time in reading (and answering
this), as I've been googling several hours for this.
Many Thanks,
E
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
> I know I could use a 'functor' defining __call__ and using member > variables, but this is more complicated and quite a bit slower. (I > also know that I can use new.function to create a new copy, but I > would like to know the rational behind the decision to make functions > atomic before I shoot myself in the foot;-) Function objects were not copyable because they were immutable. For an immutable object, a copy cannot reasonably be distinguished from the original object. See copy.py, around line 105. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 2007-05-01, Daniel Nogradi <[EMAIL PROTECTED]> wrote: >> Does sqlite come in a mac version? >> > > The interface (pysqlite) is part of the python 2.5 standard library > but you need to install sqlite itself separately (as far as I > remember) from www.sqlite.org http://developer.apple.com/documentation/MacOSX/Conceptual/OSX_Technology_Overview/AppTechnology/chapter_5_section_20.html - -- Ben Secrest <[EMAIL PROTECTED]> -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (NetBSD) iD8DBQFGNy4DeLi5NDZQ3o0RAtVOAJ9AglHEPH/9HUKIsLLWIkaNwoZC8QCaAy7T MC8VhXY2MyOyp2DaJAPOb0I= =UGAL -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
On May 1, 9:34 am, John Nagle <[EMAIL PROTECTED]> wrote: > Michael wrote: > > Why are functions atomic? (I.e. they are not copied.) > > Because Python has objects for when you need to associate > state with a function. > > John Nagle Then why are functions mutable? I can understand to some extent why functions are not picklable, because the bytecode may not be the same across python implementations (is that true?), but I do not understand why copying functions is a problem. The patch that allows copy to pass-through functions just emulates pickle, but I can find no discussion or justification for not allowing functions to be copied: http://thread.gmane.org/gmane.comp.python.devel/76636 Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: SilverLight, a new way for Python?
Re! >>> it can do much more than active scripting. Hummm Perhaps. But, with ActiveScripting, I can define functions & class in Python, Ruby(script), Jscript, VBscript, Perl. I can call these functions/objects directly from Python, and share many objects (& libraries). I am not sure to find these features in SilverLight. >>> Have you at least run the demos? Yes, I downloaded two demos, and run-it. I had look (quickly) the code. It's run. But it's too few for call that a true "try". However, these demos are nice & fun. Another thing: I have VS-2005. I had install the plug-in SilverLight/VS ; OK, but I don't found it in VS. Perhaps because I use a french version? (sorry, I don't speak english). This soft is young. I will wait some times, for read messages & realizations from new users. @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
That is the oft-quoted, idiotic type of example. The reality is that if we follow the thread, we know the question, we only want to see the answer, not wade through a morass of stuff we have already seen. If we haven't seen it, guess what, we can go and read it. "funfly3" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > David wrote: >> I am not going to join the argument, > > except you have > except to say that as you can see, I >> top post. In outlook express, you can see the messages as a thread, so >> you read the initial message, come to the reply and you read the response >> without having to scroll. Bottom posting would be fine if the previous >> message that promted the response was removed from the server, but it >> isn't, therefore, top posting is very logical. >> > only of you top post its logical as we all don't top post its not > > > A bird > > > Q name an animal that fly's > > see top posting is illogical > -- http://mail.python.org/mailman/listinfo/python-list
Re: Grabbing the output of a long-winded shell call (in GNU/Linux)
On May 1, 2:23 pm, Efrat Regev <[EMAIL PROTECTED]> wrote: > So my question is if there's a way to "grab" the output as it's being > generated. It doesn't matter if the solution is blocking (as opposed to > callback based), since threads can handle this. I just don't know how to > "grab" the output. I appreciate your time in reading (and answering > this), as I've been googling several hours for this. There may be more pythonic solution than what I suggest here but this is what I have done when I needed similar functionality. Basically run your command in the background and redirect its stdout/err to a temp file. You may run the command either in the background or in a separate thread. You can then run the command "tail --retry -- pid= -n+0 -F " and grab the output. The tail command exits once the real command is done. Raghu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Grabbing the output of a long-winded shell call (in GNU/Linux)
[EMAIL PROTECTED] wrote: > On May 1, 2:23 pm, Efrat Regev <[EMAIL PROTECTED]> wrote: > >> So my question is if there's a way to "grab" the output as it's being >> generated. It doesn't matter if the solution is blocking (as opposed to >> callback based), since threads can handle this. I just don't know how to >> "grab" the output. I appreciate your time in reading (and answering >> this), as I've been googling several hours for this. > > There may be more pythonic solution than what I suggest here but this > is what I have done when I needed similar functionality. Basically run > your command in the background and redirect its stdout/err to a temp > file. You may run the command either in the background or in a > separate thread. You can then run the command "tail --retry -- > pid= -n+0 -F " and grab the output. The tail command > exits once the real command is done. > > Raghu. > > > > Many Thanks! I'll try this -- http://mail.python.org/mailman/listinfo/python-list
Re: Generate report containing pdf or ps figures?
Cameron Laird wrote: > In article <[EMAIL PROTECTED]>, > Grant Edwards <[EMAIL PROTECTED]> wrote: >> I need to be able to generate a PDF report which consists >> mostly of vector images (which I can generate as encapsulated >> Postscript, PDF, or SVG). What I need is a way to combine >> these figures into a single PDF document. Right now the >> reports consist entire of these figures, so I just write the >> figures out to temp files and then use os.system() to run >> ghostscript with appropriate options to combine them into a >> single PDF file. >> >> I'd like to be able to add some text and/or place the figures >> in a manner other than one per page in the output document. >> >> I've looked at ReportLab's documentation, but although it >> appears to be able to use bitmap images (e.g jpeg) it doesn't >> appear to be able to use vector images (EPS/PDF/SVG). >> >> Is there a PDF generation library that can place EPS or >> PDF figures on a page? > . > . > . > You're stuck. > I have also done quite a bit of work in this area, and keep coming back to LaTeX (pdfLaTeX). For automatic document production--if you have a good quantity of very similar documents--you can produce the LaTeX from XML, hence many other input formats. The graphics need to be converted into pdf format, and you need to be careful that the vector nature of the file is preserved during this conversion, as well as transparency. Unfortunately this is still uncommon for SVG. Also Adobe seem to have lost their one-time enthusiasm for SVG, since they acquired Flash and Friends. A rather new entry into the arena is 'Altsoft Xml2PDF Workstation' which is free for command-line use, but not for server use. Seems to produce PDF of reasonable quality and to use vector format, transparency and gradient fills. Another possibility is to wrap things up as SMIL. The latest versions of Acrobat reader can use them, using RealPlayer (for example) as the actual multimedia engine. There is at least one LaTeX package that can produce PDF that incorporates such multi-media. I've rather given up on ReportLab. Trying to extend it (the free part) to use graduated fills completely did my head in! -- http://mail.python.org/mailman/listinfo/python-list
Using python with MySQL
Greetings, I need to peform some simple queries via MySQL. Searching the list I see that folks are accessing it with python. I am very new to python and pretty new to MySQL too. Would appreciate it if you could point me to some documentation for accessing MySQL via python. Something of the "Python and MySQL for Dummies" caliber would be about my speed, but of course I will be thankful for anything offered. Thanks, jvh -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
Bob Phillips wrote: > That is the oft-quoted, idiotic type of example. The reality is that if we > follow the thread, we know the question, we only want to see the answer, not > wade through a morass of stuff we have already seen. If we haven't seen it, > guess what, we can go and read it. !tuoba no gnignab ruoy tahw aedi on ev'I -- http://mail.python.org/mailman/listinfo/python-list
Re: SilverLight, a new way for Python?
"Méta-MCI" <[EMAIL PROTECTED]> wrote: > Re! > it can do much more than active scripting. > > Hummm Perhaps. > But, with ActiveScripting, I can define functions & class in Python, > Ruby(script), Jscript, VBscript, Perl. I can call these > functions/objects directly from Python, and share many objects (& > libraries). I am not sure to find these features in SilverLight. With Silverlight you can define functions & classes in Python, Ruby, JScript, C#, VB, C++, and other languages and use them interchangeably. They all run sandboxed on the client. One of the demos (the chess program) demonstrates the difference quite well: it has both JScript and C# implementations, with the JScript version examining about 500 nodes per move and the C# one about 1,500,000. > Have you at least run the demos? > > Yes, I downloaded two demos, and run-it. > I had look (quickly) the code. It's run. But it's too few for call > that a true "try". > However, these demos are nice & fun. > > > > Another thing: I have VS-2005. I had install the plug-in > SilverLight/VS ; OK, but I don't found it in VS. Perhaps because I use > a french version? (sorry, I don't speak english). As I understand it you have to install the new beta version of visual studio. So that is an 8Mb download for the Silverlight support in VS plus a 5.6Gb download for Visual Studio itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python with MySQL
On 1 May 2007 12:40:20 -0700, HMS Surprise <[EMAIL PROTECTED]> wrote: > I need to peform some simple queries via MySQL. Searching the list I > see that folks are accessing it with python. I am very new to python > and pretty new to MySQL too. Would appreciate it if you could point me > to some documentation for accessing MySQL via python. Something of the > "Python and MySQL for Dummies" caliber would be about my speed, but of > course I will be thankful for anything offered. http://mysql-python.sourceforge.net/ -- Greg Donald http://destiney.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python with MySQL
On May 1, 10:40 pm, HMS Surprise <[EMAIL PROTECTED]> wrote: > Greetings, > > I need to peform some simple queries via MySQL. Searching the list I > see that folks are accessing it with python. I am very new to python > and pretty new to MySQL too. Would appreciate it if you could point me > to some documentation for accessing MySQL via python. Something of the > "Python and MySQL for Dummies" caliber would be about my speed, but of > course I will be thankful for anything offered. > > Thanks, > > jvh hi, download this module: http://sourceforge.net/projects/mysql-python and look at the tutorial here: http://www.kitebird.com/articles/pydbapi.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python with MySQL
On May 1, 2:58 pm, "Greg Donald" <[EMAIL PROTECTED]> wrote: > On 1 May 2007 12:40:20 -0700, HMS Surprise <[EMAIL PROTECTED]> wrote: > > > I need to peform some simple queries via MySQL. Searching the list I > > see that folks are accessing it with python. I am very new to python > > and pretty new to MySQL too. Would appreciate it if you could point me > > to some documentation for accessing MySQL via python. Something of the > > "Python and MySQL for Dummies" caliber would be about my speed, but of > > course I will be thankful for anything offered. > > http://mysql-python.sourceforge.net/ > > -- > Greg Donaldhttp://destiney.com/ Most excellent! Many thanks, Greg. I'll get started reading pronto. jvh -- http://mail.python.org/mailman/listinfo/python-list
Re: Lisp-like macros in Python?
sturlamolden <[EMAIL PROTECTED]> writes: > Hello > > The Lisp crowd always brags about their magical macros. I was > wondering if it is possible to emulate some of the functionality in > Python using a function decorator that evals Python code in the stack > frame of the caller. The macro would then return a Python expression > as a string. Granted, I know more Python than Lisp, so it may not work > exactly as you expect. > > Any comments and improvements are appreciated. > > Regards, > Sturla Molden I don't know python, but check out http://www.cl-user.net/asp/libs/clpython -- Duane Rettig[EMAIL PROTECTED]Franz Inc. http://www.franz.com/ 555 12th St., Suite 1450 http://www.555citycenter.com/ Oakland, Ca. 94607Phone: (510) 452-2000; Fax: (510) 452-0182 -- http://mail.python.org/mailman/listinfo/python-list
Re: Grabbing the output of a long-winded shell call (in GNU/Linux)
Efrat Regev schrieb: > [EMAIL PROTECTED] wrote: >> On May 1, 2:23 pm, Efrat Regev <[EMAIL PROTECTED]> wrote: >> >>> So my question is if there's a way to "grab" the output as it's being >>> generated. It doesn't matter if the solution is blocking (as opposed to >>> callback based), since threads can handle this. I just don't know how to >>> "grab" the output. I appreciate your time in reading (and answering >>> this), as I've been googling several hours for this. >> >> There may be more pythonic solution than what I suggest here but this >> is what I have done when I needed similar functionality. Basically run >> your command in the background and redirect its stdout/err to a temp >> file. You may run the command either in the background or in a >> separate thread. You can then run the command "tail --retry -- >> pid= -n+0 -F " and grab the output. The tail command >> exits once the real command is done. Or instead use the python subprocess module and read the commands stdin/out/err from the Popen-object. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: relative import broken?
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I don't know of any "pretty" way -- I'd do it by path manipulation > (finding mypackage from os.path.abspath(__file__) and inserting its > _parent_ directory in sys.path). Yes, that seems to be the standard solution. I find it ugly. Anyway, I suppose my question remains: why are we constrained from solving this with a relative import? (And I suppose your answer will be: well then, relative to *what*? I am having trouble seeing why that answer cannot be given a clear riposte.) Thanks, Alan -- http://mail.python.org/mailman/listinfo/python-list
Re: SEO - Search Engine Optimization - Seo Consulting
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > You bottom posters really are a bunch of supercilious, self-righteous > bigots. > > Personally, I find bottom-posting like reading a book backwards ... it > doesn't work for me. > > And regardless of his response, Mr Bruney IS an MVP, he is clearly > knowledgeable in his subject, and his book is well enough thought of to make > me consider buying it. > > > "Sherm Pendley" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > "Juan T. Llibre" <[EMAIL PROTECTED]> writes: > > > >> Top or bottom posting is a user choice. > > > > Yes, one can choose to be polite and follow established usenet > > conventions, or one can choose to be rude and self-centered. > > > > Those who choose rudeness over courtesy can expect to be called down > > for it - which is arguably rude in itself, but on usenet one reaps what > > one sows. Someone who can't deal with that, shouldn't be on usenet. > > > > sherm-- > > > > -- > > Web Hosting by West Virginians, for West Virginians: http://wv-www.net > > Cocoa programming in Perl: http://camelbones.sourceforge.net Must be because you ARE backwards. -- Dom Robinson Gamertag: DVDfever email: dom at dvdfever dot co dot uk /* http://DVDfever.co.uk (editor) /* 1132 DVDs, 347 games, 314 CDs, 110 cinema films, 42 concerts, videos & news /* antibodies, steve hillage, burning crusade, sega psp, norah jones, kylie New music charts - http://dvdfever.co.uk/music.shtml Youtube - http://www.youtube.com/profile?user=DVDfeverDom -- http://mail.python.org/mailman/listinfo/python-list
read list of dirnames and search for filenames
I cannot seem to get this to work. I am hyst trying to read in a list
of paths and see if the directory or any sub has a filename pattern.
Here is the code:
import os, sys
from path import path
myfile = open("boxids.txt", "r")
for line in myfile.readlines():
d = path(line)
for f in d.walkfiles('*Config*.xml'):
print f
And here is my error:
Traceback (most recent call last):
File "Untitled.py", line 21, in ?
for f in d.walkfiles('*Config*.xml'):
File "C:\Python24\Lib\site-packages\path.py", line 460, in walkfiles
childList = self.listdir()
File "C:\Python24\Lib\site-packages\path.py", line 328, in listdir
names = os.listdir(self)
WindowsError: [Errno 3] The system cannot find the path specified: u'X:
\\Instructions\\97544546294\n/*.*'
What I don't get is if I just print the path it prints correctly, but
it keeps adding double "\"s to it.
I tried changing the backslashies to forward slashies and I get :
WindowsError: [Errno 3] The system cannot find the path specified:
u'X:/Instructions/97544546294\n/*.*'
help?
--
http://mail.python.org/mailman/listinfo/python-list
Python for Windows other way to getting it?
Hello I don't have permission to install new application on the PC I'm using, I need a zipped version of python that I can copy on my external drive. Where can I get a zip version? Thanks -- http://mail.python.org/mailman/listinfo/python-list
I wish that [].append(x) returned [x]
I wanted to do: query = "query text" % tuple(rec[1:-1].append(extra)) but the append() method returns none, so I did this: fields = rec[1:-1] fields.append(extra) query = "query text" % tuple(fields) -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I wish that [].append(x) returned [x]
Tobiah <[EMAIL PROTECTED]> writes: > I wanted to do: > > query = "query text" % tuple(rec[1:-1].append(extra)) > > but the append() method returns none, so I did this: > > fields = rec[1:-1] > fields.append(extra) > query = "query text" % tuple(fields) What about this? query = "query text" % tuple(rec[1:-1] + [extra]) -- HTH, Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: I wish that [].append(x) returned [x]
On May 1, 3:45 pm, Tobiah <[EMAIL PROTECTED]> wrote: > I wanted to do: > > query = "query text" % tuple(rec[1:-1].append(extra)) > > but the append() method returns none, so I did this: > > fields = rec[1:-1] > fields.append(extra) > query = "query text" % tuple(fields) > > -- > Posted via a free Usenet account fromhttp://www.teranews.com query = "query text" % tuple(rec[1:-1] + [extra]) should work. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
How can I get the ascii code of a charter in python?
Hi,
a python newbe needs some help,
I read the python doc at
http://docs.python.org/lib/module-curses.ascii.html
I tried
Import curses.asciicurses.ascii
Print ascii('a')
I get an error saying module curses.ascii8 does not exsist.
How can I get the ascii code of a charter in python?
-Ted
--
http://mail.python.org/mailman/listinfo/python-list
Re: I wish that [].append(x) returned [x]
On Tue, 2007-05-01 at 14:00 -0700, Paul McGuire wrote: > On May 1, 3:45 pm, Tobiah <[EMAIL PROTECTED]> wrote: > > I wanted to do: > > > > query = "query text" % tuple(rec[1:-1].append(extra)) > > > > but the append() method returns none, so I did this: > > > > fields = rec[1:-1] > > fields.append(extra) > > query = "query text" % tuple(fields) > > query = "query text" % tuple(rec[1:-1] + [extra]) > > should work. In addition to the above good advice, in case you are submitting a query to a DB-API compliant SQL database, you should use query parameters instead of building the query with string substitution. If you aren't querying an SQL database, never mind. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the ascii code of a charter in python?
On Tue, May 01, 2007 at 02:06:21PM -0700, [EMAIL PROTECTED] wrote:
> How can I get the ascii code of a charter in python?
It's a builtin:
>>> ord('*')
42
Dustin
--
http://mail.python.org/mailman/listinfo/python-list
Re: I wish that [].append(x) returned [x]
On May 1, 2007, at 3:45 PM, Tobiah wrote: > I wanted to do: > > query = "query text" % tuple() > > but the append() method returns none, so I did this: > > fields = rec[1:-1] > fields.append(extra) > query = "query text" % tuple(fields) > As you learned. .append() adds to an existing list rather than returning a new list. You might be happier with: query = "query text" % tuple(rec[1:-1] + [extra]) -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the ascii code of a charter in python?
[EMAIL PROTECTED] schrieb:
> Hi,
> a python newbe needs some help,
>
> I read the python doc at
> http://docs.python.org/lib/module-curses.ascii.html
>
> I tried
> Import curses.asciicurses.ascii
> Print ascii('a')
>
> I get an error saying module curses.ascii8 does not exsist.
>
> How can I get the ascii code of a charter in python?
ord('A') == 65
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: How can I get the ascii code of a charter in python?
On May 1, 2007, at 4:06 PM, [EMAIL PROTECTED] wrote:
> Hi,
> a python newbe needs some help,
>
> I read the python doc at
> http://docs.python.org/lib/module-curses.ascii.html
>
> I tried
> Import curses.asciicurses.ascii
> Print ascii('a')
>
> I get an error saying module curses.ascii8 does not exsist.
>
> How can I get the ascii code of a charter in python?
Do you mean ord()?
--
http://mail.python.org/mailman/listinfo/python-list
