Re: Mirror imaging binary numbers
"Craig" <[EMAIL PROTECTED]> wrote: > Hi there, > > I'm trying to switch binary numbers around so that the MSB becomes the > LSB etc. Is there an easy way of doing this as I can't seem to find > anything. If you could help that would be great. Thanks and good > luck. Are these Python ints, or are they "strings of bytes of known length"? And do you really want to mirror swap the binary bits or just change the byte sequence from say big to little endian? - i.e. is MSB most significant bit, or byte? assuming bit, try this: >>> num = 12345 >>> q,r = divmod(num,2) >>> q 6172 >>> r 1 >>> l = [r] >>> while q: q,r = divmod(q,2) l.append(r) >>> l [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1] >>> ans = 0 >>> for x in l: ans = ans * 2 + x >>> ans 9987 >>> and Robert is yer aunty... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
<[EMAIL PROTECTED]> wrote: > Peter> Bjoern Schliessmann wrote: > >> Wouldn't be "if k in d.keys()" be the exact replacement? > > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less > Peter> (constant) overhead for the function call. 'k in d.keys()' on the > Peter> other hand creates a list of keys which is then searched linearly > Peter> -- about the worst thing you can do about both speed and memory > Peter> footprint. > > I will admit that way back when (maybe 8 yrs ago) I actually did this in a > piece of frequently executed code that's been stable for a looong time. I > have no idea why I might have written it that way. Brain fart I suppose. I > only noticed my mistake a couple months ago during a trip into the > containing function for some other stuff. Man, was I embarrassed... why? - the main point is actually that the code worked, and was stable - that should make you proud, not embarrassed. I think that there is far too much emphasis on doing things the quickest way - as long as it works, and is fast enough, its not broken, so don't fix it... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: The del statement
Marco Aschwanden wrote: > I am not convinced though that del should also remove elements > from a container/sequence. in today's Python, you can use "del" on all targets that you can assign to. I'm not sure how breaking this consistency would somehow improve things... -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows installer for Scientific Python for Python 2.4?
On 06.12.2006, at 23:36, Grant Edwards wrote: > Can anybody point me to a windows installer for scientific > python that will work with Python 2.4? The Scientific python > download page only has an installer for Python 2.3. If you find one, please send me a copy so that I can put it on the download page! Konrad. -- - Konrad Hinsen Centre de Biophysique Moléculaire, CNRS Orléans Synchrotron Soleil - Division Expériences Saint Aubin - BP 48 91192 Gif sur Yvette Cedex, France Tel. +33-1 69 35 97 15 E-Mail: [EMAIL PROTECTED] - -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help Parsing From File
At Thursday 7/12/2006 02:51, John Machin wrote:
Gabriel Genellina wrote:
>
> ftxt=open(filename,"rt")
Never seen that done before. It's not in the docs.
A remnant of my MSDOS+C background...
FWIW:
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('foo.txt', 'rt')
>>> f = open('foo.txt', 'rs')
>>> f = open('foo.txt', 'ratsdroppings')
# Nary an exception raised, not the slightest murmur
Is this a bug or a feature? Or is it one of those good old "unspecified
behaviour" cases? MSVC rtl only?
The Python docs say only that the initial letter is checked. And the
ANSI 89 C says that other characters may follow after r, r+, etc.
"rt" is useless for an ANSI C compiler, since the default stream mode
is "text" -on systems which differentiate between text and binary-
and irrelevant on systems which don't do such distinction.
(And since I got used to write "rt", you can infer something about
*when* I began to write C programs...)
--
Gabriel Genellina
Softlab SRL
__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
--
http://mail.python.org/mailman/listinfo/python-list
Use of factory pattern in Python?
Hi, Im trying to find the best way to do a certain task and my so far I have found that using something similar to factory pattern might be the best bet. I m parsing a file to be stored as a graph (using NetworkX). Each row in the file corresponds to a node in the graph. However rows have different types and different numbers of attributes. ( and their corresponding nodes in the future will have methods ) eg chr1 SGD gene 5 8 id=1 name=3 dbref=6 chr1 SGD intron 5 6 id=5 notes="spam" chr1 SGD exon 7 8 id=5 so I was thinking of having a factory class to return the individual objects for each row..ie class Factory(): # if passed a gene return a gene object # if passed an intron return an intron object # if passed an exom return an exon object Is this a good way of doing this, or is there a better way to do this in Python, this is probably the way I d do it in Java. Many Thanks Nathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of factory pattern in Python?
Nathan Harmston wrote: > so I was thinking of having a factory class to return the individual > objects for each row..ie > > class Factory(): > # if passed a gene return a gene object > # if passed an intron return an intron object > # if passed an exom return an exon object > > Is this a good way of doing this, or is there a better way to do this > in Python in python, that's spelled: def factory(...): # if passed a gene return a gene object # if passed an intron return an intron object # if passed an exom return an exon object -- http://mail.python.org/mailman/listinfo/python-list
Window, Windows, Linux, client and server...
hi all! i'm trying to implement an appllication with this two requirements. I have a server and some clients. I want to be able to launch an application (openoffice impress, for example) and display what i'm doing on the server on the client. Conversely, I want to be able to have a picture of the desktop client. Is it a thing that i can do in python? any advice? I googled but i can't find something too useful... II know i can use vnc, but i want a pure python solution... if it's possibile... Doing it using VNC it seems not so "clear"... :) thanks, nelson -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of factory pattern in Python?
At Thursday 7/12/2006 05:28, Nathan Harmston wrote:
chr1 SGD gene 5 8 id=1 name=3 dbref=6
chr1 SGD intron 5 6 id=5 notes="spam"
chr1 SGD exon 7 8 id=5
so I was thinking of having a factory class to return the individual
objects for each row..ie
class Factory():
# if passed a gene return a gene object
# if passed an intron return an intron object
# if passed an exom return an exon object
Is this a good way of doing this, or is there a better way to do this
in Python, this is probably the way I d do it in Java.
The basic idea is the same, but instead of a long series of
if...elif...else you can use a central registry (a dictionary will
do) and dispatch on the name. Classes act as their own factories.
registry = {}
class Base(object):
kind = "Unknown"
register(Base)
class Gene(Base):
kind = "gene"
def __init__(self, *args, **kw): pass
register(Gene)
class Intron(Base):
kind = "intron"
def __init__(self, *args, **kw): pass
register(Intron)
def register(cls):
registry[cls.kind] = cls
def factory(kind, *args, **kw):
return registry[kind](*args, **kw)
If some arguments are always present, you can name them, you're not
limited to use the generic *args and **kw.
--
Gabriel Genellina
Softlab SRL
__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
--
http://mail.python.org/mailman/listinfo/python-list
Re: Use of factory pattern in Python?
Gabriel Genellina wrote:
> At Thursday 7/12/2006 05:28, Nathan Harmston wrote:
>> so I was thinking of having a factory class to return the individual
>> objects for each row..ie
>>
>> class Factory():
>> # if passed a gene return a gene object
>> # if passed an intron return an intron object
>> # if passed an exom return an exon object
>>
>> Is this a good way of doing this, or is there a better way to do this
>> in Python, this is probably the way I d do it in Java.
>
> The basic idea is the same, but instead of a long series of
> if...elif...else you can use a central registry (a dictionary will do)
> and dispatch on the name. Classes act as their own factories.
>
> registry = {}
>
> class Base(object):
> kind = "Unknown"
> register(Base)
>
> class Gene(Base):
> kind = "gene"
> def __init__(self, *args, **kw): pass
> register(Gene)
>
> class Intron(Base):
> kind = "intron"
> def __init__(self, *args, **kw): pass
> register(Intron)
>
> def register(cls):
> registry[cls.kind] = cls
>
> def factory(kind, *args, **kw):
> return registry[kind](*args, **kw)
>
And by using a metaclass on Base you can add the wizardry to have the
register-function called automatically whenever a class is derived from
Base. I also tend to use the class name instead of a separate "kind"
attribute.
registry = {}
class MetaBase(type):
def __init__(cls, name, bases, dict):
registry[name] = cls
class Base(object):
__metaclass__ = MetaBase
class Gene(Base):
def __init__(self, *args, **kw): pass
class Intron(Base):
def __init__(self, *args, **kw): pass
def factory(kind, *args, **kw):
return registry[kind](*args, **kw)
That way you don't have to think about calling the register-function
each time you derive a new class.
Regards,
Jan
--
http://mail.python.org/mailman/listinfo/python-list
Re: Re: PyRun_SimpleString no sys.argv[0]
Please keep posting on this list, surely other people can help more than I. At Thursday 7/12/2006 06:16, Ingo Wolf wrote: > At Wednesday 6/12/2006 12:23, iwl wrote: > > >I'm just starting with Python - would like to embed it in my > >windows-programm as an script-processor. For tests I use easygui some > >easy-wrapper for the py-tck-stuff. > > Looks a bit strange for me. If the GUI will be in Python, I think you > could do things the other way, *extending* your main Python program > with your own C code, not *embedding* Python inside your main C program. > I'm not sure if Tk can run without a mainloop. > No I have an Borland C++ GUI Windows App and should make it scriptable I tryed using MS ScriptControl first but have only Problems with now I try phyton which also have more posibillities. May bee I find a way to also access my script engine from outside my programm. Open and connecting some kind of terminal for my embedded phyton would also be fine. Embedding Python into your app seems fine - but in this case, your example (using Tk) is not a good starting point, since python wont use a GUI (your App is the GUI). -- Gabriel Genellina Softlab SRL __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar -- http://mail.python.org/mailman/listinfo/python-list
Re: Window, Windows, Linux, client and server...
At Thursday 7/12/2006 05:28, nelson - wrote: i'm trying to implement an appllication with this two requirements. I have a server and some clients. I want to be able to launch an application (openoffice impress, for example) and display what i'm doing on the server on the client. Conversely, I want to be able to have a picture of the desktop client. Is it a thing that i can do in python? any advice? I googled but i can't find something too useful... II know i can use vnc, but i want a pure python solution... if it's possibile... Doing it using VNC it seems not so "clear"... :) I'm not sure exactly what you want - but there are a couple of VNC clients written in Python, btw... -- Gabriel Genellina Softlab SRL __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of factory pattern in Python?
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> The basic idea is the same, but instead of a long series of
> if...elif...else you can use a central registry (a dictionary will
> do) and dispatch on the name. Classes act as their own factories.
>
> registry = {}
>
> class Base(object):
> kind = "Unknown"
> register(Base)
>
> class Gene(Base):
> kind = "gene"
> def __init__(self, *args, **kw): pass
> register(Gene)
>
> class Intron(Base):
> kind = "intron"
> def __init__(self, *args, **kw): pass
> register(Intron)
>
> def register(cls):
> registry[cls.kind] = cls
>
> def factory(kind, *args, **kw):
> return registry[kind](*args, **kw)
>
> If some arguments are always present, you can name them, you're not
> limited to use the generic *args and **kw.
If you don't want to use a register() function on each class you could
introspect like this (untested) to make the registry :-
registry = {}
for obj in sys.modules[__name__].__dict__.values():
try:
if issubclass(obj, Base):
registry[kind] = obj
except TypeError:
pass
There might be a neater way of writing the above!
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Re: PythonTidy
Chuck Rhode schrieb: > Thomas Heller wrote this on Tue, Dec 05, 2006 at 07:06:30PM +0100. My > reply is below. > >> There is still one major issue. pythonTidy uses open(input-file, >> "rb") to open the Python module to tidy up. That does not work on >> Windows, at least if the file has (as it should) "\r\n" newlines. > > Thank you for challenging my parochial world view. > > I have posted yet another version of PythonTidy: > > http://www.lacusveris.com/PythonTidy/PythonTidy-1.5.python > > This one is omnivorous wrt to newlines. > >> For output, PythonTidy generates "\n" line endings, this should also >> be changed on Windows. > > When OVERRIDE_NEWLINE = None, the first newline encountered on input > is the one used throughout the output; otherwise, you can set it to > what you want, e.g, OVERRIDE_NEWLINE = '\n'. > >> PythonTidy outputs strings with single quotes, while my own style is >> to use double quotes (I don't think that pep8 prefers one over the >> other). Is it possible to customize this? > > Here is a new global: DOUBLE_QUOTED_STRINGS = True. > Cool. You rock. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Embedded python adding variables linking to C++-Variables / callbacks
Hello, I would like to add Variables to my embedded python which represents variables from my C++-Programm. I found C-Api-funcs for adding my C-Funcs to python but none to add variables. I would like some C-Function is called when the added Python-varible is set (LValue) and some other when it is read (RValue). Can I do this. May be I have to do this in python and call the C-Funcs from a python callback. May be somebody can give short hints what to look for. -- http://mail.python.org/mailman/listinfo/python-list
Re: len() and PEP 3000
Thomas Guettler wrote: > I have read the FAQ to the len function: > http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list Outdated. You want to read the new FAQ, here: http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get all the "variables" of a string formating?
On Wed, 06 Dec 2006 10:58:56 -0800, [EMAIL PROTECTED] wrote: > "Is there an easy (i.e.: no regex) way to do get the names of all > parameters? " > > ...regexp is the easy way :D I'd like to see this regex. And make sure it works correctly with this format string: """%(key)s %%(this is not a key)d %%%(but this is)f %%%(%(and so is this)%()%%)u and don't forget the empty case %()c but not %%()E and remember to handle %(new lines)X correctly and %(percentages)%.""" It should list the keys as: 'key' 'but this is' '%(and so is this)%()%%' '' 'new\nlines' 'percentages' I love easy regexes :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess with a Python Session?
Fredrik Lundh wrote:
>> No matter what I do I cant get the following code to do what I expect.
>> I hadn't used subprocess t o read and write to pipes of a
>> still-running app, and I just can't seem to get it right. What gives?
>>
>> import subprocess
>>
>> p = subprocess.Popen("python", stdout=subprocess.PIPE,
>> stdin=subprocess.PIPE)
>> p.stdin.write('print 10\n')
>
> + p.stdin.close()
>
>> assert p.stdout.readline() == '10\n'
Yeah, but WHY was the API designed like this? Why can't I read and write
freely from a pipe connected to a process as many times as I want?
--
Giovanni Bajo
--
http://mail.python.org/mailman/listinfo/python-list
Re: how to get all the "variables" of a string formating?
> I'd like to see this regex. And make sure it works correctly with this > format string: > > """%(key)s > %%(this is not a key)d > %%%(but this is)f > %%%(%(and so is this)%()%%)u > and don't forget the empty case %()c > but not %%()E > and remember to handle %(new > lines)X correctly > and %(percentages)%.""" > > It should list the keys as: > > 'key' > 'but this is' > '%(and so is this)%()%%' > '' > 'new\nlines' > 'percentages' > > > I love easy regexes :-) >>> r = re.compile(r'(?>> print r.sub(lambda x: '@@@%s@@@' % x.group(0), s) @@@%(key)@@@s %%(this is not a key)d @@@%%%(but this is)@@@f @@@%%%(%(and so is this)@@%()@@@%%)u and don't forget the empty case @@@%()@@@c but not %%()E and remember to handle @@@%(new lines)@@@X correctly and @@@%(percentages)@@@%. >>> keys = r.findall(s) >>> keys ['key', 'but this is', '%(and so is this', '', '', 'new\nlines', 'percentages'] The extra empty item (keys[3]) is from that pathological case. Otherwise, it seems to do the trick. -tkc ps: you're a cruel, cruel fellow for throwing out such a mind-bender this early in my morning. :) Thanks for the fun! -- http://mail.python.org/mailman/listinfo/python-list
How to create a global hotkey?
I want to make a Python app that runs in the background, and when a user hits a key combination, for a function to run. This sounds simple enough, but all of the keypress detecting libraries I can find count on you creating a window and then detecting keypresses while that window has focus. I want my function to execute when the user presses the hotkey anywhere. I searched the PyGTK documentation and found an old newsgroup post where someone mentioned the C GTK+ library has it but PyGTK does not, PyQT showed no results, not sure where else I should look. I'd be willing to use a library that isn't a windowing toolkit -- I just want to be able to be able to globally detect a keypress. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Best way to split up lines - RE: About the 79 character line recommendation
Hello:
I too don't like large lines. However in the following case, and
multi-level indentations, I find it unavoidable.
Here is one huge statement I haven't been able to split onto multiple
lines.
What would be the best way to split the following line (Python doesn't like
me
to split it up between the comma-separated parameters):
top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
st2, st3, st4, st5, st6, numberOfLabels, dataWord =
struct.unpack("!H4BH20BHI", strMessage)
Thanks in advance:
Michael Yanowitz
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Ramon Diaz-Uriarte
Sent: Wednesday, December 06, 2006 5:12 PM
To: Steve Bergman
Cc: [email protected]
Subject: Re: About the 79 character line recommendation
On 5 Dec 2006 13:28:22 -0800, Steve Bergman <[EMAIL PROTECTED]> wrote:
(...)
>
> I'm finding 100 to be a nice balance. It forces me not to be lazy and
> allow really long lines, but allows me to format so as to make the
> meaning most clear.
>
But if you use some advanced editors (such as Emacs) that easily allow
you to see/edit the same file in two buffers side by side, then going
beyond 80 chars is often a bad idea, specially if you use a laptop.
(And, of course, there is the eternal issue of doing a simple "a2ps"
to print some code; longer than 80 and you often have hard to read
pages).
Best,
R.
--
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
Re: Embedded python adding variables linking to C++-Variables / callbacks
iwl ha escrito: > I would like to add Variables to my embedded python which represents > variables from my > C++-Programm. > I found C-Api-funcs for adding my C-Funcs to python but none to add > variables. > I would like some C-Function is called when the added Python-varible is > set (LValue) and > some other when it is read (RValue). Can I do this. > May be I have to do this in python and call the C-Funcs from a python > callback. Write some C functions -callable from Python- which will be used to get and set the variable value. >From inside Python, declare a property with getter and setter which will call your C functions. This works fine for object attributes. If you want to trap references to local or global "variables", I think you could provide customized dictionaries for locals and globals, but I'm not sure if it works really. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
Michael Yanowitz wrote:
> What would be the best way to split the following line (Python doesn't like
> me to split it up between the comma-separated parameters):
>
>top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
> utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
> st2, st3, st4, st5, st6, numberOfLabels, dataWord =
> struct.unpack("!H4BH20BHI", strMessage)
data = struct.unpack("!H4BH20BHI", strMessage)
(top, ip1, ip2, ip3, ip4, messageCounter, ackRequired,
dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8,
utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6,
numberOfLabels, dataWord) = data
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to create a global hotkey?
[EMAIL PROTECTED] wrote: > I want to make a Python app that runs in the background, and when a > user hits a key combination, for a function to run. This sounds simple > enough, but all of the keypress detecting libraries I can find count on > you creating a window and then detecting keypresses while that window > has focus. I want my function to execute when the user presses the > hotkey anywhere. I searched the PyGTK documentation and found an old > newsgroup post where someone mentioned the C GTK+ library has it but > PyGTK does not, PyQT showed no results, not sure where else I should > look. I'd be willing to use a library that isn't a windowing toolkit -- > I just want to be able to be able to globally detect a keypress. Any > ideas? What OS on? That is the key question here (sorry for the bad pun). It heavily depends on that, and possibly it hasn't to do with python at all, but instead configuring e.g. your window manager. Diez -- http://mail.python.org/mailman/listinfo/python-list
Common Python Idioms
Hendrik van Rooyen escreveu: > <[EMAIL PROTECTED]> wrote: > > > Peter> Bjoern Schliessmann wrote: > > >> Wouldn't be "if k in d.keys()" be the exact replacement? > > > > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less > > Peter> (constant) overhead for the function call. 'k in d.keys()' on the > > Peter> other hand creates a list of keys which is then searched linearly > > Peter> -- about the worst thing you can do about both speed and memory > > Peter> footprint. I've always used has_key(), thinking it was the only way to do it. Given that Python says that "There Should Be Only One Way to Do It", I didn't bother searching for alternatives. Is there a list somewhere listing those not-so-obvious-idioms? I've seen some in this thread (like the replacement for .startswith). I do think that, if it is faster, Python should translate "x.has_key(y)" to "y in x". Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess with a Python Session?
Shane Hathaway wrote: > > Make sure the pipes are unbuffered. Launch the process with "python -u" > and flush() the streams after writing. (That's the issue I've > encountered when doing this before.) The -u option is critical, yes. I wrote some code recently which communicated with a subprocess where the input/output exchanges aren't known in advance, and my technique involved using socket.poll and one character reads from the subprocess. I note that Pexpect is also conservative about communicating with subprocesses (see the "$ regex pattern is useless" section on the Pexpect site [1]). Generally, any work with asynchronous communications, or even socket/pipe programming in a wider sense, seems to involve ending up with working code that looks a lot like the code you started out with, but only after a period of intense frustration and with a few minor adjustments being made to separate the two. Paul [1] http://pexpect.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
Stephen Eilert wrote: > Hendrik van Rooyen escreveu: > >> <[EMAIL PROTECTED]> wrote: >> >> > Peter> Bjoern Schliessmann wrote: >> > >> Wouldn't be "if k in d.keys()" be the exact replacement? >> > >> > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less >> > Peter> (constant) overhead for the function call. 'k in d.keys()' on >> > the >> > Peter> other hand creates a list of keys which is then searched >> > linearly >> > Peter> -- about the worst thing you can do about both speed and memory >> > Peter> footprint. > > I've always used has_key(), thinking it was the only way to do it. > Given that Python says that "There Should Be Only One Way to Do It", I > didn't bother searching for alternatives. > > Is there a list somewhere listing those not-so-obvious-idioms? I've > seen some in this thread (like the replacement for .startswith). > > I do think that, if it is faster, Python should translate > "x.has_key(y)" to "y in x". How and when should it do that? Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
On Thu, 07 Dec 2006 04:08:18 -0800, Stephen Eilert wrote: > Given that Python says that "There Should Be Only One Way to Do It", Python says no such thing. Perhaps you should run "import this" at the prompt, and read _carefully_ and take note of the difference between the Zen of Python and what you wrote, because the difference is very, very significant. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: per instance descriptors
George Sakkis wrote: > Simon Bunker wrote: > > > Hi I have code similar to this: > > > > class Input(object): > > > > def __init__(self, val): > > self.value = val > > > > def __get__(self, obj, objtype): > > return self.value > > > > def __set__(self, obj, val): > > # do some checking... only accept floats etc > > self.value = val > > > > class Node(object): > > > > a = Input(1) > > b = Input(2) > > > > I realise that a and b are now class attributes - however I want to do this: > > > > node1 = Node() > > node2 = Node() > > > > node1.a = 3 > > node.b = 4 > > > > And have them keep these values per instance. However now node1.a is 4 > > when it should be 3. > > > > Basically I want to have the Input class as a gateway that does lots of > > checking when the attibute is assigned or read. > > > > I have had a look at __getattribute__(), but this gets very ugly as I > > have to check if the attribute is an Input class or not. > > > > Also I don't think property() is appropriate is it? All of the > > attributes will essentially be doing the same thing - they should not > > have individual set/get commands. > > > > Is there any way of doing this nicely in Python? > > What about __setattr__ ? At least from your example, checking happens > only when you set an attribute. If not, post a more representative > sample of what you're trying to do. > > George Yes, but I am setting it in the Node class aren't I? Wouldn't I need to define __setattr__() in class Node rather than class Input? I don't want to do this. Or am I getting confused here? thanks Simon -- http://mail.python.org/mailman/listinfo/python-list
Initializing with the correct type
Hi all, I'm new to Python and I'm just wordering if my approch is correct. Here's an example. I'm making sure that the length and types are correct. This is in case I use such a class and accidently pass it the wrong object. class Funkt: 'Funkt Class' def __init__(self, L): 'Constructer, accepts a list L of ints, which is 1 or listLength in length' if len(L) not in (1,listLength): errorString = "Format Error: L must be 1" if listLength != 1: errorString += " or "+str(listLength) errorString += " in Length" raise FormatError,errorString for i in L: if type(i) is not int: raise FormatError, "L must contain ints" class FunktError(Exception): "Exceptions base class for FUnkt class" pass class FormatError(FunktError): "Exception raised for wrong list length." def __init__(self, message): self.message = message def __str__(self): return self.message -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
"Stephen Eilert" <[EMAIL PROTECTED]> wrote: > I've always used has_key(), thinking it was the only way to do it. > Given that Python says that "There Should Be Only One Way to Do It", I > didn't bother searching for alternatives. The full quote is actually: There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. It might be more accurate to add a third line: And the one true way may change with new versions of Python In this case, dict objects used to not support the 'in' operator, but at some point it was added. I believe it wasn't there originally because Guido wasn't sure whether people would expect it should match keys or keys and values. > > Is there a list somewhere listing those not-so-obvious-idioms? I've > seen some in this thread (like the replacement for .startswith). > The release notes for each new version. Unfortunately the rest of the documentation sometimes lags behind the release notes. > I do think that, if it is faster, Python should translate > "x.has_key(y)" to "y in x". Python doesn't know whether x has a __contains__ method until it tries to call it. In particular there may be user-defined dictionary-like objects in your program which support has_key but not 'in'. e.g. in at least some versions of Zope HTTPRequest objects support has_key but not __contains__. -- http://mail.python.org/mailman/listinfo/python-list
Re: Video stream server
Fredrik Lundh wrote: > Lad wrote: > > > I love Python so I would like to implement video support in Python. > > maybe this might be helpful? > > http://blog.go4teams.com/archives/video-blogging-using-django-and-flashtm-video-flv/56 > > Yes, it is very good link. Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with closures
I can't solve your problem, but I can at least explain why I think its
hard. foo doesn't have any closed over
variables. Some of its locals have to live in cells, so that pre and
post can see them in their closures.
>>> foo.func_code.co_cellvars
('x', 'y')
Now the only way that I know of to get a local variable to be put in a
cell, where you can then plug
it into a func_closure, it to write a function which a contains a
function with a closure. Moreover, this
requires that the function signatures really match to work. Consider
>>> def test(*arg, **args):
... def inner():
... print x
... return inner
...
>>> f = test(x=5)
>>> f()
Traceback (most recent call last):
File "", line 1, in ?
File "", line 3, in inner
NameError: global name 'x' is not defined
Since x isn't a named argument of test, the compiler just assumes that
its a global.
This means that your contract function is going to have to build a
string and exec
to make the newf so its arguments match foo exactly. Of course the
compiler is
really finicky about exec, when there are free variables around, and I
don't claim
to understand the rules.
alain wrote:
> Hi,
>
> I have a problem with closures.
> I am trying to implement yet another design by contract decorator which
> would look like the following:
>
> def contract(f):
> def newf(*args, **kw):
> import new
> precondition = new.function(f.func_code.co_consts[1],
> f.func_globals,'pre',
> f.func_defaults,
> f.func_closure)
> precondition()
> result=f(*args, **kw)
> postcondition=new.function(f.func_code.co_consts[2],globals())
> postcondition(result)
> return result
> return newf
> @contract
> def foo(x,y,g=2,z=1):
> def pre():
> assert x>1 and 0 def post(result):
> assert result >0
> print 'main'
> return x+y+z*g
>
> print foo(2,5,4,69)
>
>
> The problem is that i get the following error message on line 7:
> TypeError: arg 5 (closure) must be tuple
>
> f.func_closure is indeed empty while
> f.func_code.co_consts[1].co_freevars is logically equal to ('x','y').
>
> Thanks for responding
>
> Alain
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
> - because error messages are not debugging tools (better use unit Then what are they? Machine-generated poetry? -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
Duncan Booth wrote: > In this case, dict objects used to not support the 'in' operator, but at > some point it was added. I believe it wasn't there originally because Guido > wasn't sure whether people would expect it should match keys or keys and > values. And he was right: import sys 'sys' in sys.modules => True sys in sys.modules => False Doesn't this look wrong? Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
Duncan Booth escreveu: > > > > > Is there a list somewhere listing those not-so-obvious-idioms? I've > > seen some in this thread (like the replacement for .startswith). > > > The release notes for each new version. Unfortunately the rest of the > documentation sometimes lags behind the release notes. Right. If and when time allows, I'll try to compile a list. > > > > I do think that, if it is faster, Python should translate > > "x.has_key(y)" to "y in x". > > Python doesn't know whether x has a __contains__ method until it tries to > call it. In particular there may be user-defined dictionary-like objects in > your program which support has_key but not 'in'. e.g. in at least some > versions of Zope HTTPRequest objects support has_key but not __contains__. You're right. Brain fart. Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
Stephen Eilert wrote: > I do think that, if it is faster, Python should translate > "x.has_key(y)" to "y in x". http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup -- http://mail.python.org/mailman/listinfo/python-list
Re: dict.has_key(x) versus 'x in dict'
>> I will admit that way back when (maybe 8 yrs ago) I actually did this >> in a piece of frequently executed code that's been stable for a >> looong time. I have no idea why I might have written it that way. >> Brain fart I suppose. I only noticed my mistake a couple months ago >> during a trip into the containing function for some other stuff. >> Man, was I embarrassed... Hendrik> why? - the main point is actually that the code worked, and was Hendrik> stable - that should make you proud, not embarrassed. that Hendrik> there is far too much emphasis on doing things the quickest way Hendrik> - as long as it works, and is fast enough, its not broken, so Hendrik> don't fix it... That's the rub. It wasn't fast enough. I only realized that had been a problem once I fixed it though. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
> Is there a list somewhere listing those not-so-obvious-idioms? I don't know about lists of not-so-obvious idioms, but here's some gotchas (there may be some overlap with what you're asking about): http://zephyrfalcon.org/labs/python_pitfalls.html http://www.ferg.org/projects/python_gotchas.html http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html Danny -- http://mail.python.org/mailman/listinfo/python-list
Re: per instance descriptors
[EMAIL PROTECTED] wrote: > George Sakkis wrote: > > Simon Bunker wrote: > > > > > Hi I have code similar to this: > > > > > > class Input(object): > > > > > > def __init__(self, val): > > > self.value = val > > > > > > def __get__(self, obj, objtype): > > > return self.value > > > > > > def __set__(self, obj, val): > > > # do some checking... only accept floats etc > > > self.value = val > > > > > > class Node(object): > > > > > > a = Input(1) > > > b = Input(2) > > > > > > I realise that a and b are now class attributes - however I want to do > > > this: > > > > > > node1 = Node() > > > node2 = Node() > > > > > > node1.a = 3 > > > node.b = 4 > > > > > > And have them keep these values per instance. However now node1.a is 4 > > > when it should be 3. > > > > > > Basically I want to have the Input class as a gateway that does lots of > > > checking when the attibute is assigned or read. > > > > > > I have had a look at __getattribute__(), but this gets very ugly as I > > > have to check if the attribute is an Input class or not. > > > > > > Also I don't think property() is appropriate is it? All of the > > > attributes will essentially be doing the same thing - they should not > > > have individual set/get commands. > > > > > > Is there any way of doing this nicely in Python? > > > > What about __setattr__ ? At least from your example, checking happens > > only when you set an attribute. If not, post a more representative > > sample of what you're trying to do. > > > > George > > Yes, but I am setting it in the Node class aren't I? Wouldn't I need to > define __setattr__() in class Node rather than class Input? I don't > want to do this. Or am I getting confused here? Yes, __setattr__ would be defined in Node and Input would go. It seems to me that the only reason you introduced Input was to implement this controlled attribute access, and as you see it doesn't work as you want it to. Why not define Node.__setattr__ ? George -- http://mail.python.org/mailman/listinfo/python-list
Re: Initializing with the correct type
[EMAIL PROTECTED] írta:
> Hi all,
>
> I'm new to Python and I'm just wordering if my approch is correct.
> Here's an example. I'm making sure that the length and types are
> correct. This is in case I use such a class and accidently pass it the
> wrong object.
>
> class Funkt:
> 'Funkt Class'
>
> def __init__(self, L):
> 'Constructer, accepts a list L of ints, which is 1 or
> listLength in
> length'
> if len(L) not in (1,listLength):
> errorString = "Format Error: L must be 1"
> if listLength != 1:
> errorString += " or "+str(listLength)
> errorString += " in Length"
> raise FormatError,errorString
> for i in L:
> if type(i) is not int:
> raise FormatError, "L must contain ints"
if you need something for holding only ints, you could use the array
module:
>>> import array
>>> a = array.array('i')
>>> a.append(10)
>>> a.append('foo')
Traceback (most recent call last):
File "", line 1, in ?
TypeError: an integer is required
>>> type(a)
>>>
Szabi
--
http://mail.python.org/mailman/listinfo/python-list
Re: Embedded python adding variables linking to C++-Variables / callbacks
[EMAIL PROTECTED] schrieb: > > Write some C functions -callable from Python- which will be used to get > and set the variable value. > >From inside Python, declare a property with getter and setter which > will call your C functions. > This works fine for object attributes. If you want to trap references > to local or global "variables", I think you could provide customized > dictionaries for locals and globals, but I'm not sure if it works > really. > Thank you I will try this. What I found out up to now is to create a class inherited from an fitting type and overwrite the __setitem__ and __getitem__ method but haven't test this yet, something like that: class test(int): __setitem(self, value)__: C-Set-Func(value) __getitem(self)__: return C-Get-Func() x=test() x= -> C-Set-Func called y=x -> C-Get-Func called something seems not yet correct -- http://mail.python.org/mailman/listinfo/python-list
Re: Initializing with the correct type
[EMAIL PROTECTED] wrote: > I'm new to Python and I'm just wordering if my approch is correct. > Here's an example. I'm making sure that the length and types are > correct. This is in case I use such a class and accidently pass it the > wrong object. if you go with the language instead of against it, you'll soon find that if you do accidentally pass in the wrong thing, you'll notice that pretty quickly: http://effbot.org/pytut/glossary#eafp http://effbot.org/pytut/glossary#duck-typing -- http://mail.python.org/mailman/listinfo/python-list
funcs without () like print
Hello can I make funktions callable without () like print at time the interpreter seems to printout the adres when I type the function without () -- http://mail.python.org/mailman/listinfo/python-list
Re: funcs without () like print
"iwl" <[EMAIL PROTECTED]> wrote: > Hello can I make funktions callable without () no, not really. > like print at time the interpreter seems to printout the adres when I type the > function without () the interpreter does repr() on the object (which calls the __repr__ method), and prints the result. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
>> - because error messages are not debugging tools (better use unit > > Then what are they? Machine-generated poetry? >>> me.__cmp__(gruntbuggly['freddled'].micturations, bee[LURGID].gabbleblotchits[PLURDLED]) == 0 Traceback (most recent call last): File "", line 1, in ? VogonPoetryException: Bleem miserable venchit! Bleem forever mestinglish asunder frapt! Nah...Exceptions aren't poetry...they're programmer insults akin to "You fool! How could you have let this happen!" And if things are really bad, exceptions call you "silly" :*) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a global hotkey?
> I want my function to execute when the user presses the > hotkey anywhere. Hi! - XLib unter Linux: http://python-xlib.sourceforge.net/ - wxPython unter Windows: http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey regards, Gerold :-) -- Gerold Penz - bcom - Programmierung [EMAIL PROTECTED] | http://gerold.bcom.at | http://sw3.at Ehrliche, herzliche Begeisterung ist einer der wirksamsten Erfolgsfaktoren. Dale Carnegie -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
Russ wrote: > The message tells you where the error occurred, but it doesn't tell you > what the range and the offending index are. So here is a scenario, what should happen if by accident one uses a 50Mb string as an index? Should it be displayed? i. -- http://mail.python.org/mailman/listinfo/python-list
A Call to Arms for Python Advocacy
As the Python Advocacy Coordinator, I've put up some wiki pages on the Python website for which I'm soliciting ideas, writing and graphics. Some of the material exists scattered about and just needs locating and organizing. http://wiki.python.org/moin/Advocacy First there is a need for whitepapers and flyers - I've put up a list of suggested topics w/notes at: http://wiki.python.org/moin/AdvocacyWritingTasks And there are fields for signing up for specific documents. We also have a page of possible magazine articles if that's more your style: http://wiki.python.org/moin/ArticleIdeas. These works are to be formed into advocacy kits for various audiences. So far we have the following ideas for kits: - College Student's Python Advocacy Kit - IT Department Python Advocacy Kit - University Educator's Python Advocacy Kit - K-12 Educator's Python Advocacy Kit - Research Lab Python Advocacy Kit The table of contents for the various kits can be found at: http://wiki.python.org/moin/Advocacy#AdvocacyKits Did we miss your kit? And what would you include in any of these? Next, we are seeking reusable/retargetable teaching materials, such as those under a Creative Commons license. We need slide presentations and class handouts. Now I know there are a great many slide presentations on the web about Python. I can google them all but we're not looking for just any presentation, we're looking for the best of field. You can find the collection point at: http://wiki.python.org/moin/Advocacy#TeachingMaterials Last, perhaps you can dash off an idea or two for promotional merchandise. This could be the usuals like shirts but also posters, bumper stickers and buttons. What would you like to have? And with what graphics or slogans? We can reuse some of the slogans from the PyCon Slogan Contest, but are there others? Our collection point for promo item ideas is at: http://wiki.python.org/moin/Advocacy/WearablesGadgets All materials will be credited to the authors to the extent possible by the delivery media. Make your mark. Jeff Rush <[EMAIL PROTECTED]> Python Advocacy Coordinator -- http://mail.python.org/mailman/listinfo/python-list
comtypes
comtypes seems to gain some attention (comtypes is a pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.) I'll try to release a new version over the next days. However, I'm wondering what would be the correct list to discuss this package... - the python-win32 mailing list - the ctypes-users mailing list - or should I create a new comtypes-users mailing list, mirrored on gmane, of course? Thanks for any opinions, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess with a Python Session?
Paul Boddie wrote: > Shane Hathaway wrote: > > > > Make sure the pipes are unbuffered. Launch the process with "python -u" > > and flush() the streams after writing. (That's the issue I've > > encountered when doing this before.) > > The -u option is critical, yes. I wrote some code recently which > communicated with a subprocess where the input/output exchanges aren't > known in advance, and my technique involved using socket.poll and one > character reads from the subprocess. I note that Pexpect is also > conservative about communicating with subprocesses (see the "$ regex > pattern is useless" section on the Pexpect site [1]). > > Generally, any work with asynchronous communications, or even > socket/pipe programming in a wider sense, seems to involve ending up > with working code that looks a lot like the code you started out with, > but only after a period of intense frustration and with a few minor > adjustments being made to separate the two. Is there something equivalent to the "-u" option for a shell like "bash"? In general (whether the subprocess is bash or python), how can one make sure that once something is written into the subprocess' stdin, the output from its stdout is fully completed and the subprocess is ready to receive another command? Is there some kind of signal or return status code one can capture? -- P. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
Fredrik Lundh wrote:
> Michael Yanowitz wrote:
>
> > What would be the best way to split the following line (Python doesn't like
> > me to split it up between the comma-separated parameters):
> >
> >top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
> > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
> > st2, st3, st4, st5, st6, numberOfLabels, dataWord =
> > struct.unpack("!H4BH20BHI", strMessage)
>
> data = struct.unpack("!H4BH20BHI", strMessage)
>
> (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired,
> dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8,
> utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6,
> numberOfLabels, dataWord) = data
>
>
Or simply put parentheses around the tuple on the left,
and use the ending parenthesis to get to the last line:
(top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType,
utc1,
utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11,
utc12, st1,
st2, st3, st4, st5, st6, numberOfLabels, dataWord
) = struct.unpack("!H4BH20BHI", strMessage)
John Roth
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
On 2006-12-07, Tim Chase <[EMAIL PROTECTED]> wrote: >>> - because error messages are not debugging tools (better use unit >> >> Then what are they? Machine-generated poetry? > > >>> me.__cmp__(gruntbuggly['freddled'].micturations, > bee[LURGID].gabbleblotchits[PLURDLED]) == 0 > > Traceback (most recent call last): >File "", line 1, in ? > VogonPoetryException: Bleem miserable venchit! Bleem forever > mestinglish asunder frapt! You should warn people before posting something that dangerous. I would at least have had time to pull the babelfish out of my ear, and so I could have avoided the nosebleed. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
PyCon 07
Anyone able to register yet for PyCon07? I can't find any link online..I want to get in early to lock in on the cheaper registration rate..any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
In article <[EMAIL PROTECTED]>, Jeff Rush <[EMAIL PROTECTED]> wrote: > As the Python Advocacy Coordinator, I've put up some wiki pages on the Python > website for which I'm soliciting ideas, writing and graphics. Some of the > material exists scattered about and just needs locating and organizing. > >http://wiki.python.org/moin/Advocacy I think it also appears to need faster hardware. It's running glacially slow. -- http://mail.python.org/mailman/listinfo/python-list
Jerry Brewster's new email address
hey this is arnie franks you got any tractors for sale -- http://mail.python.org/mailman/listinfo/python-list
Re: Initializing with the correct type
[EMAIL PROTECTED] wrote:
> Hi all,
>
> I'm new to Python and I'm just wordering if my approch is correct.
> Here's an example. I'm making sure that the length and types are
> correct.
Don't worry much about the type of parameters, it turns out passing
wrong data into a constructor is a problem that is both easy to avoid
and catch once it happens. Here is also an alternative to your code
try:
assert len(data) in (1, size), 'incorrect size'
assert len(data)==len( [ x for x in data if type(x)==int ] ),
'noninteger data in the list'
except Exception, exc:
raise FormatError('Data error: %s' % exc)
i.
--
http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
Roy Smith wrote: > I think it also appears to need faster hardware. It's running glacially > slow. runs fine here i. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows installer for Scientific Python for Python 2.4?
On 2006-12-07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On 06.12.2006, at 23:36, Grant Edwards wrote: > >> Can anybody point me to a windows installer for scientific >> python that will work with Python 2.4? The Scientific python >> download page only has an installer for Python 2.3. > > If you find one, please send me a copy so that I can put it on > the download page! No luck. I think I'm going to have to uninstall everything and start over with Enthought Python. God I hate working with MS-Windows... -- Grant Edwards grante Yow! Give them at RADAR-GUIDED SKEE-BALL visi.comLANES and VELVEETA BURRITOS!! -- http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
In article <[EMAIL PROTECTED]>, "Istvan Albert" <[EMAIL PROTECTED]> wrote: > Roy Smith wrote: > > > I think it also appears to need faster hardware. It's running glacially > > slow. > > runs fine here > > i. Maybe it was a transient thing -- it's running fine here too now. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
On 12/7/06, Jeff Rush <[EMAIL PROTECTED]> wrote: [snip] These works are to be formed into advocacy kits for various audiences. So far we have the following ideas for kits: - College Student's Python Advocacy Kit - IT Department Python Advocacy Kit - University Educator's Python Advocacy Kit - K-12 Educator's Python Advocacy Kit - Research Lab Python Advocacy Kit The table of contents for the various kits can be found at: http://wiki.python.org/moin/Advocacy#AdvocacyKits Did we miss your kit? And what would you include in any of these? perhaps a local python user group advocacy kit ? a PSF kit that would help LUGs to spread the good word, or some kind of support for LUGs creation also, I think we could have a european store for shirts , like the caffepress one, to lower the prices for european people and the deliver time. because in europe most Python developers won't pay 30$ for a simple shirt, that comes 3 weeks later Next, we are seeking reusable/retargetable teaching materials, such as those under a Creative Commons license. We need slide presentations and class handouts. Now I know there are a great many slide presentations on the web about Python. I can google them all but we're not looking for just any presentation, we're looking for the best of field. You can find the collection point at: http://wiki.python.org/moin/Advocacy#TeachingMaterials Last, perhaps you can dash off an idea or two for promotional merchandise. This could be the usuals like shirts but also posters, bumper stickers and buttons. What would you like to have? And with what graphics or slogans? We can reuse some of the slogans from the PyCon Slogan Contest, but are there others? Our collection point for promo item ideas is at: http://wiki.python.org/moin/Advocacy/WearablesGadgets All materials will be credited to the authors to the extent possible by the delivery media. Make your mark. Jeff Rush <[EMAIL PROTECTED]> Python Advocacy Coordinator -- http://mail.python.org/mailman/listinfo/python-list -- Tarek Ziadé | Association AfPy | www.afpy.org Blog FR | http://programmation-python.org Blog EN | http://tarekziade.wordpress.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: funcs without () like print
iwl wrote: > Hello can I make funktions callable without () like print > at time the interpreter seems to printout the adres when I type the > function without () print is not a function, it's a statement, and as such equivalent to raise or assert. Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess with a Python Session?
Giovanni Bajo wrote: >>> assert p.stdout.readline() == '10\n' > > Yeah, but WHY was the API designed like this? Why can't I read and write > freely from a pipe connected to a process as many times as I want? the subprocess module is designed to deal with Unix-style subprocesses in general, not interactive tty-based applications. you can fake it with some applications, if you make sure to flush your buffers and make sure you don't deadlock, but the right way to run an interactive tty-based application on remote is to attach it to a pseudo- tty. -- http://mail.python.org/mailman/listinfo/python-list
Re: Window, Windows, Linux, client and server...
In article <[EMAIL PROTECTED]>, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >At Thursday 7/12/2006 05:28, nelson - wrote: > >> i'm trying to implement an appllication with this two requirements. >>I have a server and some clients. I want to be able to launch an >>application (openoffice impress, for example) and display what i'm >>doing on the server on the client. Conversely, I want to be able to >>have a picture of the desktop client. Is it a thing that i can do in >>python? any advice? I googled but i can't find something too useful... >> II know i can use vnc, but i want a pure python solution... if it's >>possibile... Doing it using VNC it seems not so "clear"... :) > >I'm not sure exactly what you want - but there are a couple of VNC >clients written in Python, btw... . . . Nelson, there is GREAT technology available in this area. We don't understand your description, though. How, for example, does VNC fail to meet your requirements? When you write "a picture of the desktop client", do you have in mind a snapshot, or a "movie"? Do you want an image, or a "live" "mirror"? When you write, "I have a server and some clients", are you talking about specific applications that already exist? Do you maintain them? Are they coded in Python? What you call "this two requirements" leaves much undetermined. The more precisely you describe your needs, the more likely someone will be able to provide appropriate help. -- http://mail.python.org/mailman/listinfo/python-list
Re: funcs without () like print
print is supposed to become a function in Py3k, though. On 12/7/06, Georg Brandl <[EMAIL PROTECTED]> wrote: iwl wrote: > Hello can I make funktions callable without () like print > at time the interpreter seems to printout the adres when I type the > function without () print is not a function, it's a statement, and as such equivalent to raise or assert. -- http://mail.python.org/mailman/listinfo/python-list
Re: Inheritance doesn't work
Fredrik Lundh wrote: > J. Clifford Dyer wrote: > >> Sure, but I think the question was more about how code that references >> "MandelbrotImage could yield a stack that references MandelImage. > > well, it's been obvious for quite some time that we've now reached a > point in Python's quest for world domination where newbies start > tinkering with Python before they learn how to cut and paste text, so > I wasn't really expecting anyone to be surprised by a trivial typo. > > > Well, I can't say I was surprised, but my main (subtle, understated, sneaky) point was how do you expect anyone to help you when you aren't even giving us the proper information that produces the error? -- http://mail.python.org/mailman/listinfo/python-list
how to delete matplotlib data between ploting
I want to make few plots from CSV files. I have the code below - it
works - the first plot is ok, the second one has the first and the
current data set and so on - I can't delete the plot data between
plots.
##
# -*- coding: utf-8 -*-
from pylab import *
from os import listdir
i = listdir('dane/')
# list folders with CSV files
for di in i:
# list files in folders
csv = listdir('dane/' + di + '/')
for datafile in csv:
# open each CSV file
file = open('dane/' + di + '/' + datafile, 'r').readlines()
x = []
y = []
# get the data
for row in file:
if row.find(',') != -1:
r = row.split(',')
if len(r[0]) > 0 and len(r[1]) > 0:
x.append(float(r[0]))
y.append(float(r[1]))
xlabel('czas')
ylabel('Moc')
title(di.replace('.', ' '))
#plot
plot(x, y)
savefig('dane/' + di + '/' + datafile + '.png')
del x
del y
del file
--
http://mail.python.org/mailman/listinfo/python-list
Re: List of Events in wxPython
Jacksondf wrote: > What is that procedure for determining which events can be binded for a > particular widget? The docs don't seem to help. For example, how can I > know which events wx.SpinButton will send. > > Thanks. Exactly which docs are you looking at? The wxPython docs have a link that lists all the classes, just scroll down to that particular class and it lists the events, like hg posted. -- http://mail.python.org/mailman/listinfo/python-list
Re: funcs without () like print
iwl wrote: > Hello can I make funktions callable without () like print > at time the interpreter seems to printout the adres when I type the > function without () Hi iwl, its one of the python fundamentals when dealing with functions. function_name without the () refers to the function object, that can be passed around like any other object. function_name() with the () calls the object referred to by the function name, attempting to execute the code within it. So no. you can't call functions without the (), but python provides an easy way to know when you are calling a function or not: just look for the (). - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a global hotkey?
XLib would really only see the keys pressed when under X, do you want it to catch the keys directly from the keyboard? Gerold Penz wrote: > > I want my function to execute when the user presses the > > hotkey anywhere. > > Hi! > > - XLib unter Linux: http://python-xlib.sourceforge.net/ > - wxPython unter Windows: > http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey > > regards, > Gerold > :-) > > -- > > Gerold Penz - bcom - Programmierung > [EMAIL PROTECTED] | http://gerold.bcom.at | http://sw3.at > Ehrliche, herzliche Begeisterung ist einer der > wirksamsten Erfolgsfaktoren. Dale Carnegie -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
Fredrik Lundh wrote:
> Michael Yanowitz wrote:
>
> > What would be the best way to split the following line (Python doesn't like
> > me to split it up between the comma-separated parameters):
> >
> >top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
> > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
> > st2, st3, st4, st5, st6, numberOfLabels, dataWord =
> > struct.unpack("!H4BH20BHI", strMessage)
>
> data = struct.unpack("!H4BH20BHI", strMessage)
>
> (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired,
> dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8,
> utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6,
> numberOfLabels, dataWord) = data
>
Those utc1, ..., utc12 etc inspire a suggestion: a mild addition to the
syntax to allow specifying that the following repeat count should be
interpreted as the expected dimension of a tuple (unpack) or any
indexable object with a __len__ method (pack):
(top, ip, messageCounter, ackRequired,
dataType, utc, st, numberOfLabels, dataWord,
) = struct.unpack("! H /4B H B B /12B /6B H I", strMessage)
Apropos of a recent thread: I don't need pointing at the suggestion box
and the patch submission gizmoid on Sourceforge -- I'd be happy to do a
patch, just wondering if anybody's interested in having that, besides
me and Pat Malone :-)
Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to create a global hotkey?
If you're using python 2.4, you can use the pyHook library (I don't think it has been ported to 2.5 yet... I should email him about that), which can hook both the mouse and keyboard, so your program can be running in the background and still catch what keys (or mouse clicks) are pressed. The pyHook extension comes with some very good examples of how to use it, but if they aren't good enough examples (I can't imagine that would happen), you should check out pykeylogger (sourceforge) which uses the pyHook extension (it's a really good program. Although not like conventional keyloggers built in C/C++ which hide themselves from the OS - the purpose was not actually to spy on the user but to create backups of what was typed - it still does a very good job and the latest release has a lot of options and extendability). If your OS is linux, unix, or mac... good luck ;D Cheers, Jordan Gerold Penz wrote: > > I want my function to execute when the user presses the > > hotkey anywhere. > > Hi! > > - XLib unter Linux: http://python-xlib.sourceforge.net/ > - wxPython unter Windows: > http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey > > regards, > Gerold > :-) > > -- > > Gerold Penz - bcom - Programmierung > [EMAIL PROTECTED] | http://gerold.bcom.at | http://sw3.at > Ehrliche, herzliche Begeisterung ist einer der > wirksamsten Erfolgsfaktoren. Dale Carnegie -- http://mail.python.org/mailman/listinfo/python-list
Re: how to delete matplotlib data between ploting
pylab.clf() or some such thing clears the current canvas.
[EMAIL PROTECTED] wrote:
> I want to make few plots from CSV files. I have the code below - it
> works - the first plot is ok, the second one has the first and the
> current data set and so on - I can't delete the plot data between
> plots.
> ##
> # -*- coding: utf-8 -*-
> from pylab import *
> from os import listdir
>
> i = listdir('dane/')
>
> # list folders with CSV files
> for di in i:
> # list files in folders
> csv = listdir('dane/' + di + '/')
> for datafile in csv:
> # open each CSV file
> file = open('dane/' + di + '/' + datafile, 'r').readlines()
> x = []
> y = []
> # get the data
> for row in file:
> if row.find(',') != -1:
> r = row.split(',')
> if len(r[0]) > 0 and len(r[1]) > 0:
> x.append(float(r[0]))
> y.append(float(r[1]))
> xlabel('czas')
> ylabel('Moc')
> title(di.replace('.', ' '))
> #plot
> plot(x, y)
> savefig('dane/' + di + '/' + datafile + '.png')
> del x
> del y
> del file
--
http://mail.python.org/mailman/listinfo/python-list
Re: how to delete matplotlib data between ploting
clf() works :) thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help Parsing From File
Gabriel Genellina wrote:
> At Thursday 7/12/2006 02:51, John Machin wrote:
>
> >Gabriel Genellina wrote:
> > >
> > > ftxt=open(filename,"rt")
> >
> >Never seen that done before. It's not in the docs.
>
> A remnant of my MSDOS+C background...
>
> >FWIW:
> >
> >Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
> >(Intel)] on win
> >32
> >Type "help", "copyright", "credits" or "license" for more information.
> > >>> f = open('foo.txt', 'rt')
> > >>> f = open('foo.txt', 'rs')
> > >>> f = open('foo.txt', 'ratsdroppings')
> ># Nary an exception raised, not the slightest murmur
> >
> >Is this a bug or a feature? Or is it one of those good old "unspecified
> >behaviour" cases? MSVC rtl only?
>
> The Python docs say only that the initial letter is checked. And the
> ANSI 89 C says that other characters may follow after r, r+, etc.
> "rt" is useless for an ANSI C compiler, since the default stream mode
> is "text" -on systems which differentiate between text and binary-
> and irrelevant on systems which don't do such distinction.
> (And since I got used to write "rt",
Why did you do that?
(1) Text mode is was and ever shall be the default, even with MS.
(2) Seeing we're referring to docs and standards: Microsoft C 5.0
Optimizing Compiler, Run-Time Library Reference manual says "The t
option is not part of the ANSI standard for open, but is a Microsoft
extension and should not be used where ANSI portability is required".
> you can infer something about
> *when* I began to write C programs...)
Youngster :-)
Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list
feed-forward neural network for python
Hi! I released feed-forward neural network for python (ffnet) project at sourceforge. Implementation is extremelly fast (code written mostly in fortran with thin python interface, scipy optimizers involved) and very easy to use. I'm announcing it here because you, folks, are potential users/testers. If anyone is interested please visit http://ffnet.sourceforge.net (and then post comments if any...) Greetings -- Marek Wojciechowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
In article <[EMAIL PROTECTED]>,
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
> Michael Yanowitz wrote:
>
> > What would be the best way to split the following line (Python doesn't like
> > me to split it up between the comma-separated parameters):
> >
> >top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
> > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
> > st2, st3, st4, st5, st6, numberOfLabels, dataWord =
> > struct.unpack("!H4BH20BHI", strMessage)
>
> data = struct.unpack("!H4BH20BHI", strMessage)
>
> (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired,
> dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8,
> utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6,
> numberOfLabels, dataWord) = data
>
>
My general rule of thumb for formatting things like argument lists is
either they all fit on one line, or they go one item per line. So, I would
do it:
(top,
ip1,
ip2,
ip3,
ip4,
messageCounter,
ackRequired,
dataType,
utc1,
utc2,
utc3,
utc4,
utc5,
utc6,
utc7,
utc8,
utc9,
utc10,
utc11,
utc12,
st1,
st2,
st3,
st4,
st5,
st6,
numberOfLabels,
dataWord) = data
All one one line, it's just a mess of text to read through. Formatting
like this, it immediately (at least to my eyes) jumps out that you've got a
bunch of ips, a few other things, a bunch of utcs, a bunch of sts, and then
some more random data. Much easier to read.
The downside, of course, it it takes up mumble lines instead of 4. I'm
cool with that, but I could see how it might annoy some people.
It would be nice if struct.unpack() had a way to specify unpacking repeated
items as a list, ie:
data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage)
(top,
ip,
messageCounter,
ackRequired,
dataType,
utc,
st,
numberOfLables,
dataWord) = data
and you'd end up with ip, utc, and st being lists. Hmmm, maybe that's
worth a PEP?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character line recommendation
Michael Yanowitz schreef:
> Hello:
>
>I too don't like large lines. However in the following case, and
> multi-level indentations, I find it unavoidable.
>Here is one huge statement I haven't been able to split onto multiple
> lines.
> What would be the best way to split the following line (Python doesn't like
> me
> to split it up between the comma-separated parameters):
>
> top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
> utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
> st2, st3, st4, st5, st6, numberOfLabels, dataWord =
> struct.unpack("!H4BH20BHI", strMessage)
I see three possibilities:
1. Avoid the one-liner alltogether
u = struct.unpack("!H4BH20BHI", strMessage)
top = u[0]
ip1, ip2, ip3, ip4 = u[1:5]
messageCounter = u[6]
# ... and so on ...
In this approach with your example it seems to me to be a good idea to
put ip, utc and st in separate tuples like this:
u = struct.unpack("!H4BH20BHI", strMessage)
top = u[0]
ip = u[1:5]
messageCounter = u[5]
ackRequired = u[6]
dataType = u[7]
utc = u[8:20]
st = u[20:26]
numberOfLabels = u[26]
dataWord = u[27]
2. Use parens around the tuple on the left hand side
(top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12,
st1, st2, st3, st4, st5, st6, numberOfLabels,
dataWord) = struct.unpack("!H4BH20BHI", strMessage)
3. Use '\' to break the line
top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, \
utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, \
utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord \
= struct.unpack("!H4BH20BHI", strMessage)
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
Daniel Dittmar wrote:
> Duncan Booth wrote:
> > In this case, dict objects used to not support the 'in' operator, but at
> > some point it was added. I believe it wasn't there originally because Guido
> > wasn't sure whether people would expect it should match keys or keys and
> > values.
>
> And he was right:
>
> import sys
> 'sys' in sys.modules => True
> sys in sys.modules => False
>
> Doesn't this look wrong?
No it doesn't look wrong to anyone who has read the docs on
sys.modules. And it's irrelevant. The comparison should be between
'sys' in sys.modules # match keys
and
('sys', sys) in sys.modules # match keys and values
not
sys in sys.modules # match values
In any case, dict values can be any old object and may not even support
an equality test -- matching keys only seems the only reasonable choice
to me.
Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list
makeactivexclass stopped giving me events when i upgraded to wxpython 2.7 =(
Hi all.
I just upgraded to wxpython 2.7
Its way cool.
However, in one of my apps, i have embedded a flash activex control.
I have had it working great in wxpython 2.6.
After i upgraded to 2.7, i stopped receiving events from flash!
But whats even weirder is that when i embed the flash activex in a wx.Frame
instead of a wx.Panel, i do get the flash events!
I am most mystifieddoes anyone have any idea here?
thanks all,
matt
Heres the trimmed down version of the code that used to give me events:
Note that when i change the wx.Panel to wx.Frame, i start getting the events
again.
#panel for displaying activex flash
class FlashPanel(wx.Panel):
def __init__(self, parent, id=-1):
wx.Panel.__init__(self, parent, id)
self.parent = parent
self.InitWindowProperties()
self.CreateFlashPlayer()
def InitWindowProperties(self):
print 'initializing flash interface...'
self.FlashPlayerTopSizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.FlashPlayerTopSizer)
self.SetAutoLayout(True)
self.Show(True)
#create the activex flash
def CreateFlashPlayer(self):
FlashModule =
win32com.client.gencache.EnsureModule('{D27CDB6B-AE6D-11CF-96B8-44455354}',
0,1,0)
FlashActiveXClass = MakeActiveXClass(FlashModule.ShockwaveFlash,
eventObj=self)
self.FlashPlayer = FlashActiveXClass(self, -1)
self.FlashPlayerTopSizer.Add(self.FlashPlayer, 1, wx.EXPAND)
#callback for when a call is made from flash to python
def OnFlashCall(self, *Args): print 'got a callback from flash!'
_
Share your latest news with your friends with the Windows Live Spaces
friends module.
http://clk.atdmt.com/MSN/go/msnnkwsp007001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mk
--
http://mail.python.org/mailman/listinfo/python-list
Re: feed-forward neural network for python
mwojc wrote: > Hi! > I released feed-forward neural network for python (ffnet) project at > sourceforge. Implementation is extremelly fast (code written mostly in > fortran with thin python interface, scipy optimizers involved) and very > easy to use. > I'm announcing it here because you, folks, are potential users/testers. > > If anyone is interested please visit http://ffnet.sourceforge.net (and > then post comments if any...) Thanks for making available your code. The Fortran code compiles with both g95 and gfortran. I looked at the code briefly, and it is well-documented and clear, but I do wonder why you are writing new code in Fortran 77. Using free source form instead of fixed source form would make the code more readable, and using the array operations of Fortran 90 would make it more concise. Gfortran is a Fortran 95 compiler and is part of gcc, so using Fortran 95 features should not inhibit portability. I think using the single letter "o" as a variable name is a bad idea -- it looks too much like "0". I would like to see a Fortran driver (main program) for the code, so I could see an example of its use independent from Python and f2py. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
Roy Smith wrote:
> It would be nice if struct.unpack() had a way to specify unpacking repeated
> items as a list, ie:
>
>data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage)
>(top,
> ip,
> messageCounter,
> ackRequired,
> dataType,
> utc,
> st,
> numberOfLables,
> dataWord) = data
>
> and you'd end up with ip, utc, and st being lists.
:-)
Extension: if you used [] in the format string, the results would be
tuples.
:-)
> Hmmm, maybe that's
> worth a PEP?
Great minds think more-or-less alike :-)
All we need now is for the populace to vote on "least fugly syntax".
Yours has the advantage over mine that it would handle (say) 10(4s)
*if* anybody ever wanted to do that, but the ")" is a redundant
nuisance.
Mine could be changed so that the "/" is between the count and the
format code, so that 10/4s would work ... hmmm there are actually 3
different numbers: an overall repeat count, a tuple/list length, and a
field width. The current syntax uses the one number as a field width
for "s" and as a repeat count for other format codes. Ugh.
BTW the only reason I picked "/" was it doesn't need the Shift key :-)
Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
In article <[EMAIL PROTECTED]>,
"John Machin" <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote:
>
> > It would be nice if struct.unpack() had a way to specify unpacking repeated
> > items as a list, ie:
> >
> >data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage)
> >(top,
> > ip,
> > messageCounter,
> > ackRequired,
> > dataType,
> > utc,
> > st,
> > numberOfLables,
> > dataWord) = data
> >
> > and you'd end up with ip, utc, and st being lists.
>
> :-)
> Extension: if you used [] in the format string, the results would be
> tuples.
> :-)
I see your point. Actually, I think you want to force the sequences to be
lists (regardless of what syntax we end up with), on the theory that tuples
are for heterogeneous sequences and lists are for homogeneous ones. As for
the parens, I was thinking fortran-style format specifiers, which may or
may not be the best model for a modern language :-)
> > Hmmm, maybe that's
> > worth a PEP?
>
> Great minds think more-or-less alike :-)
I was in the process of writing one up when I saw your earlier post. I'll
mail you a draft when I've got it done.
--
http://mail.python.org/mailman/listinfo/python-list
Can't 'register' to Cheese Shop from command line..only web + egg dependency question
I seem to be able to register and upload from web site but not command line. Command line register attempts keep giving " Server response (401): Authorization Required" Any ideas? & What must I do to make installation of my egg also install dependencies? I did an install and noticed other eggs didn't come along for the ride. Chris -- http://mail.python.org/mailman/listinfo/python-list
write an update manager in python/wxPython
Hello all I have a small application for which I would like to write an update manager. I assume that the basics of it is to compare versions of the user's current application and a new one store in a new file on a particular URL. Now is there any standard way to do that. I am sure I can figure out something. But instead of designing something new from scratch that may end up to be full of bugs, maybe some existing classes in python, wxPython or within the win32com package exist. Any thoughts? Thank you all M.E. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to split up lines - RE: About the 79 character linerecommendation
Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
> "John Machin" <[EMAIL PROTECTED]> wrote:
>
> > Roy Smith wrote:
> >
> > > It would be nice if struct.unpack() had a way to specify unpacking
> > > repeated
> > > items as a list, ie:
> > >
> > >data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage)
> > >(top,
> > > ip,
> > > messageCounter,
> > > ackRequired,
> > > dataType,
> > > utc,
> > > st,
> > > numberOfLables,
> > > dataWord) = data
> > >
> > > and you'd end up with ip, utc, and st being lists.
> >
> > :-)
> > Extension: if you used [] in the format string, the results would be
> > tuples.
> > :-)
>
> I see your point. Actually, I think you want to force the sequences to be
> lists (regardless of what syntax we end up with), on the theory that tuples
> are for heterogeneous sequences and lists are for homogeneous ones.
And array.arrays are for sequences that are even more homogeneous :-)
However, after reflection I'd go for lists on practical grounds,
because they're mutable and tuples aren't -- often one wants to start
fiddling with the input.
> As for
> the parens, I was thinking fortran-style format specifiers, which may or
> may not be the best model for a modern language :-)
Yes, please don't perpetuate 10HANTIQUATED concepts :-)
>
> > > Hmmm, maybe that's
> > > worth a PEP?
> >
> > Great minds think more-or-less alike :-)
>
> I was in the process of writing one up when I saw your earlier post. I'll
> mail you a draft when I've got it done.
Great. Looking forward to it.
Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
John Machin wrote: > It should be extremely easy (rather than "not impossible") for > anybody with half a clue > Sheesh. > And despite your use of RHN (Reverse Hungarian Notation) you don't > know that someList is a list? I appreciate your taking the time to post this thoughtful and civil reply not once but six times. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't 'register' to Cheese Shop from command line..only web + egg dependency question
[EMAIL PROTECTED] wrote: > I seem to be able to register and upload from web site but not command > line. Command line register attempts keep giving " Server response > (401): Authorization Required" > > Any ideas? You probably need to set up a .pypirc file in your home directory. Info here: http://www.python.org/~jeremy/weblog/030924.html > > & What must I do to make installation of my egg also install > dependencies? I did an install and noticed other eggs didn't come > along for > the ride. Your setup.py file should have a "install_requires" parameter to the setup function. Most likely it is a list. Add the names of the projects you are trying to require and (optionally) the version. Here is a sample: install_requires = [ "FooBar", # installs latest version of 'FooBar' "Stump >= 1.0b2"], # installs 'Stump' of version 1.0b2 or later Full docs on this are here: http://peak.telecommunity.com/DevCenter/setuptools -Adam > > Chris -- http://mail.python.org/mailman/listinfo/python-list
Multithreaded python script calls the COMMAND LINE
I have python script does ftp download in a multi threaded way. Each thread downloads a file, close the file, calls the comman line to convert the .doc to pdf. Command line should go ahead and convert the file. My question is, when each thread calls the command line, does one command line process all the request, or each thread creates a one command line process for themselves and executes the command? For some reason I am getting "File '1' is alread exists, Do you want to overwrite [y/n]?" I have to manually enter 'y' or 'n' for the python script to complete. -- http://mail.python.org/mailman/listinfo/python-list
SOAP Server with WSDL?
I'm having trouble finding information about writing a SOAP server. I get the client part. There is much information about writing a client, but not so much about writing the server. Are there some good tutorials? I'm checking out: http://pywebsvcs.sourceforge.net/ But I'm a little confused. Do I want ZSI or SOAPY? The site says: SOAPpy: A second web services toolkit which is getting functionally integrated into the ZSI toolkit. In the future, the Python Web Services Project will only support one merged web services toolkit, under the ZSI name. This make me think that I will use ZSI in the future, but what about now? Do I need both now? Thanks, Toby -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not just show the out-of-range index?
OKB (not okblacke) wrote: > John Machin wrote: > > It should be extremely easy (rather than "not impossible") for > > anybody with half a clue > > > Sheesh. > > And despite your use of RHN (Reverse Hungarian Notation) you don't > > know that someList is a list? > > I appreciate your taking the time to post this thoughtful and civil > reply not once but six times. > You should direct your appreciation to Google Groups for 5 out of the 6 times -- it was stating incorrectly that it had not posted due to a 502 error; I have since removed those. Yes, it was thoughtful and civil compared to some earlier postings in this thread, wasn't it? I do hope that you didn't confuse (your interpretation of) the manner with the message: again, extremely high cost-to-benefit ratio. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedded python adding variables linking to C++-Variables / callbacks
On 7 dic, 11:33, "iwl" <[EMAIL PROTECTED]> wrote: > What I found out up to now is to create a class inherited from an > fitting type > and overwrite the __setitem__ and __getitem__ method but haven't test > this > yet, something like that: > > class test(int): > __setitem(self, value)__: C-Set-Func(value) > __getitem(self)__: return C-Get-Func() > > x=test() > x= -> C-Set-Func called > y=x -> C-Get-Func called Python doesn't work that way: http://effbot.org/zone/python-objects.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Multithreaded python script calls the COMMAND LINE
On 7 dic, 17:36, "johnny" <[EMAIL PROTECTED]> wrote: > I have python script does ftp download in a multi threaded way. Each > thread downloads a file, close the file, calls the comman line to > convert the .doc to pdf. Command line should go ahead and convert the > file. My question is, when each thread calls the command line, does one > command line process all the request, or each thread creates a one > command line process for themselves and executes the command? For some > reason I am getting "File '1' is alread exists, Do you want to > overwrite [y/n]?" I have to manually enter 'y' or 'n' for the python > script to complete. That depends on how you invoke it: os.system creates a new shell which in turn creates a new process; the spawn* functions do that directly. Anyway, if you have many conversion processes running, you should pass them unique file names to avoid conflicts. Where does the '1' name come from? If it's you, don't use a fixed name - the tempfile module may be useful. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Call to Arms for Python Advocacy
Jeff Rush wrote:
> These works are to be formed into advocacy kits for various audiences. So far
> we have the following ideas for kits:
>
>- College Student's Python Advocacy Kit
>- IT Department Python Advocacy Kit
>- University Educator's Python Advocacy Kit
>- K-12 Educator's Python Advocacy Kit
>- Research Lab Python Advocacy Kit
>
> The table of contents for the various kits can be found at:
>
>http://wiki.python.org/moin/Advocacy#AdvocacyKits
>
> Did we miss your kit? And what would you include in any of these?
[coming_from[lang].advocacy_kit
for lang in ('C/C++', 'Java', 'Perl', 'PHP', 'Visual Basic')]
(the six more popular than Python according to
http://www.tiobe.com/tpci.htm)
George
--
http://mail.python.org/mailman/listinfo/python-list
Re: SOAP Server with WSDL?
On Thu, Dec 07, 2006 at 12:49:09PM -0800, tobiah wrote: > I'm having trouble finding information > about writing a SOAP server. I get the client > part. There is much information about writing > a client, but not so much about writing the server. > Are there some good tutorials? > > I'm checking out: > > http://pywebsvcs.sourceforge.net/ > > But I'm a little confused. Do I want ZSI or SOAPY? You want ZSI. If you already have a wsdl you then use wsdl2py and wsdl2dispatch to create your server classes. The server classes get used with ZSI.ServiceContainer. Unfortunately there is not much documentation about this. I figured it out by playing with the tests that ship with ZSI. You might also want to check out ZSI the mailing list/archives which you can get to from the above link. > The site says: > > SOAPpy: A second web services toolkit which is getting > functionally integrated into the ZSI toolkit. In the > future, the Python Web Services Project will only support > one merged web services toolkit, under the ZSI name. > > This make me think that I will use ZSI in the future, > but what about now? Do I need both now? You only need ZSI. > > Thanks, > > Toby > > -- > Posted via a free Usenet account from http://www.teranews.com > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution time of lines within a function
On Dec 4, 2006, at 11:36 PM, Paul McGuire wrote: > The PythonDecoratorLibrary page on the Python wiki has a link to a > @profile > decorator, that I have used to profile the contents of targeted > functions > (only just now, I don't seem to be able to get to the wiki to get > the exact > link). http://mg.pov.lt/blog/profilehooks-1.0.html Note that the license has been changed from GPL to MIT, making it distributable with non-GPL projects. -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Re: memory error with matplot
> "lisa" == lisa engblom <[EMAIL PROTECTED]> writes:
lisa> Hi, I am using matplotlib with python to generate a bunch of
lisa> charts. My code works fine for a single iteration, which
lisa> creates and saves 4 different charts. The trouble is that
lisa> when I try to run it for the entire set (about 200 items) it
lisa> can run for 12 items at a time. On the 13th, I get an error
lisa> from matplotlib that says it can't access data. However, if
lisa> I start the program at the point it failed before it works
lisa> fine and will create the charts for the next 12 before
lisa> failing. I assume that I am not closing the files properly
lisa> somehow or otherwise misallocating memory. I tried just
lisa> reimporting pylab each iteration, but that didn't help.
lisa> This is the function that creates a chart:
There are a couple of things to try. First, on a long shot, does it
help to do
close(1)
instead if simply close(). I don't think it will but worth a try.
Second, I think there is a small leak in the tkcanvas, but not in
matplotlib proper. Do you need to display the graphs you are
creating, or do you merely want to save them? If the latter, simply
use the Agg backend
import matplotlib
matplotlib.use('Agg')
*before* you import pylab.
Finally, if you are still having troubles, post a complete,
free-standing, script to the matplotlib mailing list and we'll see if
we can replicate it.
You may also want to take a look at the FAQ on memory leaks:
http://matplotlib.sourceforge.net/faq.html#LEAKS
JDH
--
http://mail.python.org/mailman/listinfo/python-list
Re: Common Python Idioms
Danny Colligan wrote: > > Is there a list somewhere listing those not-so-obvious-idioms? > > I don't know about lists of not-so-obvious idioms, but here's some > gotchas (there may be some overlap with what you're asking about): > > http://zephyrfalcon.org/labs/python_pitfalls.html > http://www.ferg.org/projects/python_gotchas.html > http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html > > Danny I'm surprized that none of these pages mentions the incompatible type comparison gotcha: >>> 5 < "4" True I'm sure this has bitten many folks, particularly (ex) Perl'ers. George -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP Server with WSDL?
> You want ZSI. If you already have a wsdl you then use wsdl2py and > wsdl2dispatch to create your server classes. The server classes get used > with ZSI.ServiceContainer. Unfortunately there is not much documentation > about this. Actually, do I have to make a WSDL? Do people hand write these, or are there tools? I don't really need to publish an interface. I just want some in house apps to communicate. I can't figure out if I want SOAP, or CORBA, or would it just be easier if I just starting opening sockets and firing data around directly. Ideally, I'd like to share complex objects. That's why I thought that I needed one of the above standards. I'm confused by it all. Am I even looking in the right direction? Thanks, Toby -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: write an update manager in python/wxPython
[EMAIL PROTECTED] wrote: > Hello all > I have a small application for which I would like to write an update > manager. I assume that the basics of it is to compare versions of the > user's current application and a new one store in a new file on a > particular URL. > Now is there any standard way to do that. I am sure I can figure out > something. But instead of designing something new from scratch that may > end up to be full of bugs, maybe some existing classes in python, > wxPython or within the win32com package exist. > Any thoughts? Dont think there is a standard way of doing it. The way I have done it in my applications is to keep an ini file containing the version number, which is downloaded and compared against the version of the app. That part is trivial to implement in python with urllib. I just point the user at the download url when there is a new version. It would require a little more effort if you want to have some kind of automatic update... Will McGugan -- blog: http://www.willmcgugan.com -- http://mail.python.org/mailman/listinfo/python-list
