Re: gamma approximation : what is module cmath and where is it located ?
Chris Rebert wrote: > On Wed, Jul 29, 2009 at 11:41 PM, Peter Otten<[email protected]> wrote: >> [email protected] wrote: >> >>> I've used python a few months and expected to find cmath seperately >>> sort of as a " header file". A text search failed. I now understand >>> its in the Python Standard Library, which I assume is that big file >>> Python30\LIBS\libpython30.a >> >> Python 3.1 is no longer maintained. I recommend that you upgrade to >> Python 3.1. > > (He meant to say 3.0.x is no longer maintained.) Ouch. Thanks for the correction. -- http://mail.python.org/mailman/listinfo/python-list
beautiful soup
hi, everyone Is there any pakage or module handling html document like beautiful soup? thanks a lot -- http://mail.python.org/mailman/listinfo/python-list
Re: beautiful soup
xubin.cz schrieb: hi, everyone Is there any pakage or module handling html document like beautiful soup? why don't you *use* beautiful soup? It is a module... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: beautiful soup
On 30 Jul 2009, at 09:30 , Diez B. Roggisch wrote: xubin.cz schrieb: hi, everyone Is there any pakage or module handling html document like beautiful soup? why don't you *use* beautiful soup? It is a module... Or lxml, which works a bit better than BF 3.1 (post parser change) nowadays. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Hi! > Python is interpreted No. Python is compiled (--> .pyc) But the term "to compile" is not always unambiguous... And the notion of "compiler" is not attached to Python (the language), but is attached to the implementation. @+ MCI -- http://mail.python.org/mailman/listinfo/python-list
Bug in IEHtmlWindow?
Hi everyone, I'm trying to use IEHtmlWindow in my application (python 2.5, wxpython 2.8 on win xp). Everything is ok, but I encountered a problem which also affects the demo. If I make a research on google a strange message appears, saying (I'll try to translate from italian): Error during execution. Do you want to run the debug? line 29: error: 'r' is NULL or it is not an object Did anybody have the same problem? is it a bug? Thanks in advance for your help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Marcus Wanner wrote: Look for example to libusb, which provides a userspace environment and pyusb which uses that and provides an interface to Python. iicr pyusb uses a c interface to libusb, not python... According to them they use ctypes indeed. Sorry if I was misleading in my explanation. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Michel Claveau - MVP wrote: Hi! Python is interpreted No. Python is compiled (--> .pyc) But the term "to compile" is not always unambiguous... And the notion of "compiler" is not attached to Python (the language), but is attached to the implementation. @+ MCI Well the pyc, which I thought was the Python bytecode, is then interpreted by the VM. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
string.Template issue
Hello, In the string.Template documentation (http://docs.python.org/library/string.html) it's explained that if a custom regular expression for pattern substitution is needed, it's possible to override idpattern class attribute (whose default value is [_a-z][_a-z0-9]*). However, if the custom pattern that is needed is just uppercase letters something like [A-Z]+ won't work because of the following line in the _TemplateMetaclass class __init__ method: cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE) I would say that this is an error (IGNORECASE just shouldn't be there) and that the line above should be: cls.pattern = _re.compile(pattern, _re.VERBOSE) and the default value for idpattern: [_a-zA-Z][_a-zA-Z0-9]* Do you agree on this? Is there any reason for the IGNORECASE option to be passed to re.compile? Best regards, Javier -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Martin P. Hellwig wrote: > Well the pyc, which I thought was the Python bytecode, is then > interpreted by the VM. Python is often referred as byte-code interpreted language. Most modern languages are interpreted languages. The list [1] is rather long. Technically speaking even native code is interpreted by the micro code of most CPUs. [1] http://en.wikipedia.org/wiki/Interpreted_language [2] http://en.wikipedia.org/wiki/Microcode -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
Hi Dave, Your solution sort of defeats my intended purpose (sorry for not divulging my 'hidden agenda'). I wanted my application to "hide" the fact that it's a python script, and look as much as possible like it's a compiled program. The reason I don't just give my user a py file, is that I don't want a cleaver user to change the innards of the script. On the other hand, I don't want to make a compiled (freezed?) version of the application, because it'll grow the resulting file significantly, and I don't have the experience to know how it will run on different Linuxes. Bye, Ron. Hey Ron, What i usually do to accomplish this is compile the script to a .pyc just like you did and then call that pyc from another script that's not compiled. so in your case the not compiled script looks like: #!/usr/bin/env python import test_pyc.pyc then run that script... hope this helps... alternatively you might have a look at: http://www.pyinstaller.org/ gr Arno-- http://mail.python.org/mailman/listinfo/python-list
Pyplot
I am a newbee in Python. I have some problem with usage of Pyplot. I have a loop that creates plot in every end of it. Problem starts here: The first plot is fine but the second one is plotted onto the first plot. I use: plt.cla() plt.draw() plt.hold(False) plt.close() plt.clf() but nothing works. Perhaps I am having a problem with basics, please help me if you know something about it. Kaan -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
Barak, Ron wrote: > Your solution sort of defeats my intended purpose (sorry for not divulging my > 'hidden agenda'). > I wanted my application to "hide" the fact that it's a python script, and > look as much as possible like it's a compiled program. > The reason I don't just give my user a py file, is that I don't want a > cleaver user to change the innards of the script. > On the other hand, I don't want to make a compiled (freezed?) version of the > application, because it'll grow the resulting file significantly, and I don't > have the experience to know how it will run on different Linuxes. Ask Google for binfmt-support. Hint: Each Python version has its own magic header. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyplot
Please help me I have been dealing with this little piece of code for 2
days. I am stuck and loosing time with it.
plt.figure(count)
plt.xlabel("Time steps")
plt.ylabel("Values")
plt.title("Output of ADCs")
plt.plot(timing,adc0)
plt.plot(timing,adc1)
plt.plot(timing,adc3)
plt.show()
plt.clf()
plt.cla()
plt.close()
30 Temmuz 2009 11:02 tarihinde Kaan AKŞİT yazdı:
> I am a newbee in Python. I have some problem with usage of Pyplot. I have a
> loop that creates plot in every end of it. Problem starts here: The first
> plot is fine but the second one is plotted onto the first plot. I use:
>
> plt.cla()
> plt.draw()
> plt.hold(False)
> plt.close()
> plt.clf()
>
> but nothing works. Perhaps I am having a problem with basics, please help
> me if you know something about it.
>
> Kaan
>
--
http://mail.python.org/mailman/listinfo/python-list
Can you easy_install from your localhost?
I have a package i would like to store locally. If it is stored locally can I do something like ' easy_install http://localhost/package ' ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: set variable to looping index?
Martin:
> for f in var1_fn, var2_fn, var3_fn:
> if f.split('.')[0] == 'var1':
> var1 = call_some_function(f)
> .
> .
> .
> etc
As usual I have big problems in understanding what you want to do.
Please, show an example of the contents of var1_fn, var2_fn, etc.
Generally you can create a dict:
results = {}
And then fill it with name-result pairs:
name = value.split('_')[0]
results[name] = some_function(value)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Compiling Python for uCLinux appliance?
Hello I just got a small appliance based on a Blackfin CPU with 64MB RAM and 258MB NAND flash. Using the stock software, there's about 30MB of RAM left. Besides C/C++ and shel scripts, I was wondering if it were realistic to upload a few Python scripts in such a small appliance? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can you easy_install from your localhost?
Ronn Ross schrieb: > I have a package i would like to store locally. If it is stored locally can > I do something like ' easy_install http://localhost/package ' ? Thanks You can do: easy_install /path/to/package-0.1.tar.gz or you can put your packages into /some/directory/simple/packagename/package-0.1.tar.gz and do: easy_install -i file:///some/directory packagename Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: gamma approximation : what is module cmath and where is it located ?
On Wed, 29 Jul 2009 21:34:07 -0700, Chris Rebert wrote: > The difference is that it handles complex numbers, whereas the plain > "math" module doesn't. > I would guess the reason there are separate modules is for performance, > so as to avoid having to dispatch on type at runtime. But this is only a > guess. My understanding is that it is to avoid people who don't care about complex numbers being confused when math.sqrt(-1) returns 1j instead of raising an error. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Help on Reading Attached Image on Excel
Anyone know how to read included images in Excel using Python? I've tried xlrd and pyexcelerator, but i couldn't figure out how to do it. If anyone has experience in this, please help. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: gamma approximation : what is module cmath and where is it located ?
On Thu, Jul 30, 2009 at 3:10 AM, Steven D'Aprano wrote: > On Wed, 29 Jul 2009 21:34:07 -0700, Chris Rebert wrote: > >> The difference is that it handles complex numbers, whereas the plain >> "math" module doesn't. >> I would guess the reason there are separate modules is for performance, >> so as to avoid having to dispatch on type at runtime. But this is only a >> guess. > > My understanding is that it is to avoid people who don't care about > complex numbers being confused when math.sqrt(-1) returns 1j instead of > raising an error. That seems a better and more plausible rationale than my guess. Kudos. - Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
On Thu, 30 Jul 2009 07:01:28 +0100, Barak, Ron wrote: > I wanted my application to "hide" the fact that it's a python script, > and look as much as possible like it's a compiled program. What do you think the "c" in .pyc stands for? What it's not is a compiled to machine-code stand alone executable. > The reason I don't just give my user a py file, is that I don't want > a cleaver user to change the innards of the script. It's not the clever users you need to worry about, because they'll fix your bugs. It's the not-as-clever-as-they-think-they-are users you have to worry about. But frankly, the best way to deal with them is to make it absolutely clear that you don't provide free support for modified versions of the script, and as soon as they report a problem, you diff their version with the official version. If they vary, then you start charging them. Before you go spending vast amounts of time and energy creating a fragile solution, it's worth you working out what it actually is you're trying to prevent. If it's just "I don't want anybody touching my precious, precious code!" then I have no sympathy and have no interest in helping you. If it's "The damn users have mucked up the script AGAIN and now they expect me to fix it for free!!!", then that's a social problem, not a technical one, and a social solution might save you a lot of wasted effort. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: socket send
On Jul 30, 5:52 am, NighterNet wrote: > I am trying to figure out how to send text or byte in python 3.1. I am > trying to send data to flash socket to get there. I am not sure how to > work it. > > buff= 'id=' , self.id , ':balive=False\n' > clientSock.send(buff); Try putting a 'b' before the constant string that you want to send: >>> type(b'123') or use something like this to convert non constant strings (with only ASCII characters) into bytes: >>> s = "A non-constant string : %d " % n >>> s 'A non-constant string : 12 ' >>> type(s) >>> b = bytes ( ord(c) for c in s ) >>> b b'A non-constant string : 12 ' You could also use struct.pack , that in python 3.x returns bytes and not strings. In this case you need to specify the size of the string (extra bytes are zero-filled): import struct >>> struct.pack( "30s", "A non-constant string : %d " % n ) b'A non-constant string : 12 \x00\x00\x00' Ciao - FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
r wrote: My adventures in Ruby. Oh, it's you. Good boy. Now, why don't you have a look at javascript and come back in six months? Or better yet, haskell and twelve months. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
On Tuesday 28 July 2009, Christopher Arndt wrote:
> setup(name='regex',
> version='1.0',
> py_modules = ['regex'],
> ext_modules=[Extension('_regex', ['_regex.c'])],
> )
>
> Also, you need to copy "unicodedata_db.h" from the "Modules"
> directory of the Python source tree to your working directory,
> since this file apparently is not installed into the include
> directory of a Python installation.
using issue2636-20090729.zip
I have Python 2.6.2 on ubuntu 9.04
with ggc-4.3:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c _regex.c -o
build/temp.linux-i686-2.6/_regex.o
_regex.c: In Funktion »bmatch_context«:
_regex.c:1462: Fehler: Als Erhöhungsoperand wird L-Wert erfordert
_regex.c:1470: Fehler: Als Erhöhungsoperand wird L-Wert erfordert
_regex.c:1478: Fehler: Als Verringerungsoperand wird L-Wert erfordert
with gcc-4.4:
gcc-4.4 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-
prototypes -fPIC -I/usr/include/python2.6 -c _regex.c -o
build/temp.linux-i686-2.6/_regex.o
_regex.c: In function ‘bmatch_context’:
_regex.c:1462: error: lvalue required as increment operand
_regex.c:1470: error: lvalue required as increment operand
_regex.c:1478: error: lvalue required as decrement operand
--
Wolfgang
--
http://mail.python.org/mailman/listinfo/python-list
RE: Run pyc file without specifying python path ?
From: PythonAB [mailto:[email protected]] Sent: Thursday, July 30, 2009 12:18 To: Barak, Ron Cc: 'Dave Angel'; '[email protected]' Subject: Re: Run pyc file without specifying python path ? Hi Dave, Your solution sort of defeats my intended purpose (sorry for not divulging my 'hidden agenda'). I wanted my application to "hide" the fact that it's a python script, and look as much as possible like it's a compiled program. The reason I don't just give my user a py file, is that I don't want a cleaver user to change the innards of the script. On the other hand, I don't want to make a compiled (freezed?) version of the application, because it'll grow the resulting file significantly, and I don't have the experience to know how it will run on different Linuxes. Bye, Ron. Hey Ron, What i usually do to accomplish this is compile the script to a .pyc just like you did and then call that pyc from another script that's not compiled. so in your case the not compiled script looks like: #!/usr/bin/env python import test_pyc.pyc then run that script... hope this helps... alternatively you might have a look at: http://www.pyinstaller.org/ gr Arno [BR] Thanks for the answer Arno. But, I wonder - How is your suggestion, which to the user would look like: python wrapper.py different (from the user's point-of-view) than the following: python test_pyc.pyc ? I'm trying to avoide having to write python on the command line. Of course, I could write the wrapper is bourne shell, but that interoduces other problems (especially when considering that my real application needs to parse many command line options). . Bye, Ron. -- http://mail.python.org/mailman/listinfo/python-list
Python processors? : WAS Re: Does python have the capability for driver development ?
On Jul 30, 11:10 am, Christian Heimes wrote: > Martin P. Hellwig wrote: > > Well the pyc, which I thought was the Python bytecode, is then > > interpreted by the VM. > > Python is often referred as byte-code interpreted language. Most modern > languages are interpreted languages. The list [1] is rather long. > Technically speaking even native code is interpreted by the micro code > of most CPUs. > > [1]http://en.wikipedia.org/wiki/Interpreted_language > [2]http://en.wikipedia.org/wiki/Microcode Once upon a time there where lisp machines, whith processors designed to fastly execute lisp code ... I worked with one of them for 2 years. I wonder: has anybody thought of making a python-machine, or at least a processor able to directly execute high-level bytecode (LLVM-like?). I think the main feature of such a machine should be hyper-fast hash lookup. Then dynamic memory management hardware ... Ciao - FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
On Thu, Jul 30, 2009 at 3:42 AM, Barak, Ron wrote: > > > > From: PythonAB [mailto:[email protected]] > Sent: Thursday, July 30, 2009 12:18 > To: Barak, Ron > Cc: 'Dave Angel'; '[email protected]' > Subject: Re: Run pyc file without specifying python path ? > > > Hi Dave, > Your solution sort of defeats my intended purpose (sorry for not divulging > my 'hidden agenda'). > I wanted my application to "hide" the fact that it's a python script, and > look as much as possible like it's a compiled program. > The reason I don't just give my user a py file, is that I don't want a > cleaver user to change the innards of the script. > On the other hand, I don't want to make a compiled (freezed?) version of the > application, because it'll grow the resulting file significantly, and I > don't have the experience to know how it will run on different Linuxes. > Bye, > Ron. > > Hey Ron, > What i usually do to accomplish this is compile the script to a .pyc just > like you > did and then call that pyc from another script that's not compiled. > so in your case the not compiled script looks like: > #!/usr/bin/env python > import test_pyc.pyc > > > then run that script... > hope this helps... > > > alternatively you might have a look at: > http://www.pyinstaller.org/ > > > gr > Arno > [BR] Thanks for the answer Arno. But, I wonder - > > How is your suggestion, which to the user would look like: > python wrapper.py No, with the shebang line (and assuming execute permissions on the file), it would look like: ./wrapper.py (or just `wrapper.py` depending on whether the file is placed in the $PATH) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
Wolfgang Rohdewald wrote:
On Tuesday 28 July 2009, Christopher Arndt wrote:
setup(name='regex',
version='1.0',
py_modules = ['regex'],
ext_modules=[Extension('_regex', ['_regex.c'])],
)
Also, you need to copy "unicodedata_db.h" from the "Modules"
directory of the Python source tree to your working directory,
since this file apparently is not installed into the include
directory of a Python installation.
using issue2636-20090729.zip
I have Python 2.6.2 on ubuntu 9.04
with ggc-4.3:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c _regex.c -o
build/temp.linux-i686-2.6/_regex.o
_regex.c: In Funktion »bmatch_context«:
_regex.c:1462: Fehler: Als Erhöhungsoperand wird L-Wert erfordert
_regex.c:1470: Fehler: Als Erhöhungsoperand wird L-Wert erfordert
_regex.c:1478: Fehler: Als Verringerungsoperand wird L-Wert erfordert
with gcc-4.4:
gcc-4.4 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-
prototypes -fPIC -I/usr/include/python2.6 -c _regex.c -o
build/temp.linux-i686-2.6/_regex.o
_regex.c: In function ‘bmatch_context’:
_regex.c:1462: error: lvalue required as increment operand
_regex.c:1470: error: lvalue required as increment operand
_regex.c:1478: error: lvalue required as decrement operand
There are other lines which are similar, eg line 1487. Do they all give
the same/similar error with your compiler?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On 30 Jul 2009, at 06:04 , alex23 wrote:
On Jul 30, 1:06 pm, r wrote:
1.) No need to use "()" to call a function with no arguments.
Python --> "obj.m2().m3()" --ugly
Ruby --> "obj.m1.m2.m3" -- sweeet!
Man, i must admit i really like this, and your code will look so much
cleaner.
How do you distinguish between calling a method with no arguments, and
getting access to the method object itself (because it _is_ an object,
y'know, it's OO all the way down...)?
As chris pointed out, there's a method for that, to which a symbol is
provided: `Object#method(methodname)`, which is basically equivalent
to `getattr(object, methodname)` in Python.
2.) the .each method
container.each{|localVar| block}
This method can really cleanup some ugly for loops, although i really
like the readability of for loops.
map(lambda localVar: , sequence)
or:
def usefully_named_func(var):
return var
transformed = [usefully_named_func(v) for v in sequence]
The issue here is of course that `map` and comprehensions are
transformations. `#each` exists for effectful iterations (Ruby has
`#map` for the map operation). So the intent expressed by `#each` and
`map` isn't the same. Furthermore and this is the most problematic
limitation of Python here, `lambda` doesn't allow complex
transformations due to its restrictions, so one has to switch to named
functions which works but isn't sexy (and tends to lower readability
imo).
3.) true OOP
Now before you go and get all "huffy" over this statement, hear me
out. Python is the best language in the world. But it damn sure has
some warts! "len(this)" instead of "obj.length" max(that) instead of
[1,2,3,4,5].max().
As the Zen says: '[P]racticality beats purity'. Personally, I'm not
sure how a handful of convenient built-in functions make a language in
which _everything is an object_ somehow "false" OO.
That's an interesting point, but not relevant at the end of the day:
`foo.length` and `length(foo)` have the same "practicality". On the
other hand Ruby can be praised for the coherence: everything's a
method period end of the story; while Python does have a dichotomy
between methods and functions/generic methods (whether or not that
dichotomy bothers users is another issue).
With max(), this is a built-in that takes _any_ iterable and an
optional key function, and returns the highest value as per the key.
This means that _every_ iterable object - as _well_ as every object
that supports enough of the iterator protocol - can be handed to max()
and a result obtained. So at best, I just need to make sure my new
sequence-type provides the iterator protocol and viola, it works with
max() without me having to hand-code a .max() that's specialised for
my new type, and without Python forcing me to have a complex
inheritance chain just to make sure I include the right
MaxableSequence ancestor to inherit the right .max().
Well interestingly, Ruby works pretty much the same way. Where Python
asks that you implement the iterator protocol to have `max` work, Ruby
asks that you implement the `each` method (also called the Enumerable
protocol) and mixin `Enumerable` (http://ruby-doc.org/core/classes/Enumerable.html
). Then you get max (and min, map, etc…) "for free". Of course you're
free to re-implement all of them manually if you wish to do so (or if
you need those operations to return your custom collection rather than
arrays). Enumerable is merely a convenience mixin. So there's no big
difference here (and note that mixins aren't necessarily part of the
inheritance chain, though they're implemented that way in Ruby).
Also, it's "voilà" not "viola" (a viola is a bowed string instrument,
slightly bigger than a violin, whereas voilà is a french interjection
used to call attention or suggest the appearance of something, as if
by magic).
PS stay tuned for more from this series
Is this going to be more of you telling us - without any apparent
irony whatsoever - how Ruby has some valid points after all your
vilification last year when we said the same to you? If so, where can
I sign up?!
I fear I'll have to agree with that sentiment.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Does underscore has any special built-in meaningin Python ?
Ben Finney a écrit : dandi kain writes: What is the functionality of __ or _ , leading or trailing an object , class ot function ? Please note that in Python, classes and functions are objects too. But anyway, these underscores are part of *identifiers*, not objects themselves !-) foo Ordinary name, part of public interface _foo Ordinary name, part of internal-only interface __fooOrdinary name, but will be mangled (this style used rarely) __foo__ Name which is used in a special way by Python And FWIW: foo_ When you want to use a reserved name for identifier (ie: 'class_' , 'or_', 'and_' etc) -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
Masklinn wrote: ... That's an interesting point, but not relevant at the end of the day: `foo.length` and `length(foo)` have the same "practicality". On the other hand Ruby can be praised for the coherence: everything's a method period end of the story; while Python does have a dichotomy between methods and functions/generic methods (whether or not that dichotomy bothers users is another issue). ... how would you correct a newbie (like me) who says: "well, the main difference between a function and a method (from the caller's pow) is a syntactic one: fun(obj, arguments) as opposed to: obj.met(arguments) but the effect is just about the same." ? bye -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a dream language: sounds like Python to me.
> Where can I find a Python functionality like simulink ? Stef, I saw this at: http://showmedo.com/videotutorials/video?name=743&fromSeriesID=743 Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
superpollo wrote: Masklinn wrote: ... That's an interesting point, but not relevant at the end of the day: `foo.length` and `length(foo)` have the same "practicality". On the other hand Ruby can be praised for the coherence: everything's a method period end of the story; while Python does have a dichotomy between methods and functions/generic methods (whether or not that dichotomy bothers users is another issue). ... how would you correct a newbie (like me) who says: "well, the main difference between a function and a method (from the caller's pow) is a syntactic one: fun(obj, arguments) as opposed to: obj.met(arguments) but the effect is just about the same." ? bye My suggestion - OO programming: length(foo) calls the foo instance(or class for some language) length method length(bar) calls the bar instance length method, it is **not** the same than the foo method - non OO programming: length(foo) calls the length function with foo as parameter length(bar) calls the **same** length function with the bar parameter (so you better make sure length is handling both foo and bar) So the difference is definitely **not** a syntactic one, but it is true that the syntax obj.method() better illustrates the bind mechanism of the OO programming. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Python processors? : WAS Re: Does python have the capability for driver development ?
On Thu, Jul 30, 2009 at 3:49 AM, Francesco Bochicchio wrote: > On Jul 30, 11:10 am, Christian Heimes wrote: >> Martin P. Hellwig wrote: >> > Well the pyc, which I thought was the Python bytecode, is then >> > interpreted by the VM. >> >> Python is often referred as byte-code interpreted language. Most modern >> languages are interpreted languages. The list [1] is rather long. >> Technically speaking even native code is interpreted by the micro code >> of most CPUs. >> >> [1]http://en.wikipedia.org/wiki/Interpreted_language >> [2]http://en.wikipedia.org/wiki/Microcode > > Once upon a time there where lisp machines, whith processors designed > to fastly execute lisp code ... I worked with one of them for 2 > years. > I wonder: has anybody thought of making a python-machine, or at least > a processor able to directly execute high-level bytecode (LLVM-like?). > I think the main feature of such a machine should be hyper-fast hash > lookup. Then dynamic memory management hardware ... Yes, it was considered a decade ago: http://mail.python.org/pipermail/python-list/1999-June/004451.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
On Thursday 30 July 2009, MRAB wrote: > There are other lines which are similar, eg line 1487. Do they all > give the same/similar error with your compiler? yes. The full output with gcc-4.3: notebook:~/kmj/src$ LANG=C python setup.py build running build running build_py running build_ext building '_regex' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c _regex.c -o build/temp.linux-i686-2.6/_regex.o _regex.c: In function 'bmatch_context': _regex.c:1462: error: lvalue required as increment operand _regex.c:1470: error: lvalue required as increment operand _regex.c:1478: error: lvalue required as decrement operand _regex.c:1487: error: lvalue required as decrement operand _regex.c:1593: error: lvalue required as increment operand _regex.c:1606: error: lvalue required as decrement operand _regex.c:1616: error: lvalue required as increment operand _regex.c:1625: error: lvalue required as increment operand _regex.c:1634: error: lvalue required as decrement operand _regex.c:1643: error: lvalue required as decrement operand _regex.c:2036: error: lvalue required as increment operand _regex.c:2047: error: lvalue required as increment operand _regex.c:2059: error: lvalue required as decrement operand _regex.c:2070: error: lvalue required as decrement operand _regex.c:2316: error: lvalue required as increment operand In file included from _regex.c:2431: _regex.c: In function 'umatch_context': _regex.c:1462: error: lvalue required as increment operand _regex.c:1470: error: lvalue required as increment operand _regex.c:1478: error: lvalue required as decrement operand _regex.c:1487: error: lvalue required as decrement operand _regex.c:1593: error: lvalue required as increment operand _regex.c:1606: error: lvalue required as decrement operand _regex.c:1616: error: lvalue required as increment operand _regex.c:1625: error: lvalue required as increment operand _regex.c:1634: error: lvalue required as decrement operand _regex.c:1643: error: lvalue required as decrement operand _regex.c:2036: error: lvalue required as increment operand _regex.c:2047: error: lvalue required as increment operand _regex.c:2059: error: lvalue required as decrement operand _regex.c:2070: error: lvalue required as decrement operand _regex.c:2316: error: lvalue required as increment operand error: command 'gcc' failed with exit status 1 -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On 30 Jul 2009, at 14:03 , superpollo wrote: Masklinn wrote: ... That's an interesting point, but not relevant at the end of the day: `foo.length` and `length(foo)` have the same "practicality". On the other hand Ruby can be praised for the coherence: everything's a method period end of the story; while Python does have a dichotomy between methods and functions/generic methods (whether or not that dichotomy bothers users is another issue). ... how would you correct a newbie (like me) who says: "well, the main difference between a function and a method (from the caller's pow) is a syntactic one: fun(obj, arguments) as opposed to: obj.met(arguments) but the effect is just about the same." ? Depending on the way things are implemented, it can be very similar (see CLOS' generic functions, which have the same look as functions but dispatch based on parameter types). In Python, the difference would be that functions don't automatically dispatch (you have a function for everybody, and any dispatch you perform based on argument types or other qualifiers has to be done manually) whereas methods do dispatch on the first [implied] argument (you execute a precise method corresponding to the object it's being called on). So fun(obj, *arguments) will call the same `fun` whether `obj` is an int, a string or an HTTPFactory whereas obj.met(*arguments) will call a different `met` each time (they all have the same "unqualified" name [and signature if it's part of a protocol], but might very well be implemented completely differently). Therefore -- in python -- the effect isn't anywhere "just about the same". -- http://mail.python.org/mailman/listinfo/python-list
Regexp problem
Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'something-is-listening', i need to get the something part, use it in my code, and then replace the whole 'something-is-listening' for another string. Someone can help me please? Thank you! -- http://mail.python.org/mailman/listinfo/python-list
Re: gamma approximation : what is module cmath and where is it located ?
On Wed, 29 Jul 2009 23:24:11 -0500, pdlemper wrote: > The following numerical approximation for Euler's Gamma function > is found in http://en.wikipedia.org/wiki/Lanczos_approximation > > from cmath import * > This works in Python 3.0 > > But I can't figure out where it gets "cmath".Searching the Python > directory reveals no more than a test_cmath. The only cmath I can find > is a header file in another directory turboc++\Borland\include\ > > dir(cmath) reveals 23 functions overlapping the 37 functions of > the math module. > > What is cmath, where did it come from and how does it differ from > the standard math module ? If you're looking for the file, it's written in C, so it's typically a dynamic library, e.g.: /usr/lib/python2.5/lib-dynload/cmath.so You won't find a cmath.py file. -- http://mail.python.org/mailman/listinfo/python-list
Image merging
Hi, I need to create an app that takes to images and mergers them. After googling around I have found 4 graphic library's that I can use. However since I am new to "image programming" can you please tell me which one you think would be the best. The ones I found were cairographics PIL Imagemagick GraphicsMagick Any tips? Thanks James -- http://www.goldwatches.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
On 30 jul 2009, at 12:57, Chris Rebert wrote: On Thu, Jul 30, 2009 at 3:42 AM, Barak, Ron wrote: From: PythonAB [mailto:[email protected]] Sent: Thursday, July 30, 2009 12:18 To: Barak, Ron Cc: 'Dave Angel'; '[email protected]' Subject: Re: Run pyc file without specifying python path ? Hi Dave, Your solution sort of defeats my intended purpose (sorry for not divulging my 'hidden agenda'). I wanted my application to "hide" the fact that it's a python script, and look as much as possible like it's a compiled program. The reason I don't just give my user a py file, is that I don't want a cleaver user to change the innards of the script. On the other hand, I don't want to make a compiled (freezed?) version of the application, because it'll grow the resulting file significantly, and I don't have the experience to know how it will run on different Linuxes. Bye, Ron. Hey Ron, What i usually do to accomplish this is compile the script to a .pyc just like you did and then call that pyc from another script that's not compiled. so in your case the not compiled script looks like: #!/usr/bin/env python import test_pyc.pyc then run that script... hope this helps... alternatively you might have a look at: http://www.pyinstaller.org/ gr Arno [BR] Thanks for the answer Arno. But, I wonder - How is your suggestion, which to the user would look like: python wrapper.py No, with the shebang line (and assuming execute permissions on the file), it would look like: ./wrapper.py (or just `wrapper.py` depending on whether the file is placed in the $PATH) Cheers, Chris yes exactly, chris you can distribute a pyc containing your program, and have the wrapper.py execute it gr Arno -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
Wolfgang Rohdewald wrote: On Thursday 30 July 2009, MRAB wrote: There are other lines which are similar, eg line 1487. Do they all give the same/similar error with your compiler? yes. The full output with gcc-4.3: notebook:~/kmj/src$ LANG=C python setup.py build running build running build_py running build_ext building '_regex' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall - Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c _regex.c -o build/temp.linux-i686-2.6/_regex.o _regex.c: In function 'bmatch_context': _regex.c:1462: error: lvalue required as increment operand [snip] error: command 'gcc' failed with exit status 1 So it complains about: ++(RE_CHAR*)context->text_ptr but not about: ++info->repeat.count Does this mean that the gcc compiler thinks that the cast makes it an rvalue? I'm using Visual C++ 2008 Express Edition, which doesn't complain. What does the C standard say? -- http://mail.python.org/mailman/listinfo/python-list
RE: Run pyc file without specifying python path ?
Barak, Ron wrote: -Original Message- From: Dave Angel [mailto:[email protected]] Sent: Wednesday, July 29, 2009 21:05 To: Barak, Ron Cc: '[email protected]' Subject: Re: Run pyc file without specifying python path ? Barak, Ron wrote: Hi, I wanted to make a python byte-code file executable, expecting to be able to run it without specifying "python" on the (Linux bash) command line. So, I wrote the following: [r...@vmlinux1 python]# cat test_pyc.py #!/usr/bin/env python print "hello" [r...@vmlinux1 python]# and made its pyc file executable: [r...@vmlinux1 python]# ls -ls test_pyc.pyc 4 -rwxr-xr-x 1 root root 106 Jul 29 14:22 test_pyc.pyc [r...@vmlinux1 python]# So, I see: [r...@vmlinux1 python]# file test_pyc.py* test_pyc.py: a python script text executable test_pyc.pyc: python 2.3 byte-compiled [r...@vmlinux1 python]# If I try to do the following, no problem: [r...@vmlinux1 python]# python test_pyc.pyc hello [r...@vmlinux1 python]# However, the following fails: [r...@vmlinux1 python]# ./test_pyc.pyc -bash: ./test_pyc.pyc: cannot execute binary file [r...@vmlinux1 python]# Is there a way to run a pyc file without specifying the python path ? Bye, Ron. I don't currently run Unix, but I think I know the problem. In a text file, the shell examines the first line, and if it begins #! it's assumed to point to the executable of an interpreter for that text file. Presumably the same trick doesn't work for a .pyc file. Why not write a trivial wrapper.py file, don't compile it, and let that invoke the main code in the .pyc file? Then make wrapper.py executable, and you're ready to go. DaveA Hi Dave, Your solution sort of defeats my intended purpose (sorry for not divulging my 'hidden agenda'). I wanted my application to "hide" the fact that it's a python script, and look as much as possible like it's a compiled program. The reason I don't just give my user a py file, is that I don't want a cleaver user to change the innards of the script. On the other hand, I don't want to make a compiled (freezed?) version of the application, because it'll grow the resulting file significantly, and I don't have the experience to know how it will run on different Linuxes. Bye, Ron. Most of the other answers basically paraphrased my suggestion of making a wrapper file, not compiling it, and making it executable. With that approach, the user just types "wrapper.py" on his command line. And wrapper.py only needs two lines, a shebang, and an import, no big deal if the user modifies it. The rest of your code can be .pyc files. Steven makes some good points. You have to define what level of clever you're protecting from. A determined hacker will get in no matter what you do, unless you want to ship the program in a proprietary embedded system, encased in epoxy. Further, if you have an extension of .py or .pyc, a knowledgeable hacker will know it's probably python. You imply you want it to run unmodifed on multiple unknown Linux versions. I think that lets out binfmt solutions. That means you need to test and support not only multiple Linux implementations, but multiple Python versions, because who knows what the user may have installed. I think you need to rethink your support strategy. And maybe concentrate on being able to detect change, rather than prevent it. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Regexp problem
I have a problem and i'm not very good at regular expressions.
I have a text like "lalala lalala tiruri beldar-is-listening tiruri
lalala" I need a regexp to get the 'beldar' part, the format is
'something-is-listening', i need to get the something part, use it in
my code, and then replace the whole 'something-is-listening' for
another string.
Pretty easy:
>>> import re
>>> s = "lalala lalala tiruri beldar-is-listening tiruri lalala"
>>> r = re.compile(r'(\w+)-is-listening')
>>> r.search(s).group(1)
'beldar'
>>> r.sub('this is a replacement', s)
'lalala lalala tiruri this is a replacement tiruri lalala'
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
Re: Regexp problem
Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'something-is-listening', i need to get the something part, use it in my code, and then replace the whole 'something-is-listening' for another string. \w+ will match a word and enclosing it in (...) will capture what was matched: m = re.search(r"(\w+)-is-listening", text) print "Captured '%s'" % m.group(1) print "Matched from %d to %d" % (m.start(), m.end()) -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
On Thursday 30 July 2009, MRAB wrote:
> So it complains about:
>
> ++(RE_CHAR*)context->text_ptr
>
> but not about:
>
> ++info->repeat.count
>
> Does this mean that the gcc compiler thinks that the cast makes it
> an rvalue? I'm using Visual C++ 2008 Express Edition, which doesn't
> complain. What does the C standard say?
I am not really a C expert but I found some links. Most helpful:
http://developer.apple.com/DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/C-Dialect-Options.html
(search -fnon-lvalue-assign)
so I did the conversion mentioned there. This works:
--- _regex.c2009-07-29 11:34:00.0 +0200
+++ n 2009-07-30 15:15:22.0 +0200
@@ -1459,7 +1459,7 @@
if (text_ptr < (RE_CHAR*)context->slice_end && text_ptr[0] != '\n')
{
context->node = node->next_1;
-++(RE_CHAR*)context->text_ptr;
+++*(RE_CHAR**)&context->text_ptr;
} else
context = reject_context(state, context);
break;
--
Wolfgang
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python ctypes on win64
On Jul 25, 3:09 am, [email protected] (Aahz) wrote: > In article , Thanks, I'll try there. > > ulf wrote: > > >Does anybody know if python includes a win64 version ofctypes? > > >According to the documentation it should be included - at least > >there's no special remarks for win64, and I haven't found any recent > >notes saying that it shouldn't work on win64. Yet it looks like both > >the installer from Python.org and from ActiveState.com have disabled > >it. > > Nobody seems to have followed up to this, you may have better luck on > the capi-sig mailing list. > -- > Aahz ([email protected]) <*> http://www.pythoncraft.com/ > > "At Resolver we've found it useful to short-circuit any doubt and just > refer to comments in code as 'lies'. :-)" > --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Martin P. Hellwig wrote: Michel Claveau - MVP wrote: Hi! Python is interpreted No. Python is compiled (--> .pyc) But the term "to compile" is not always unambiguous... And the notion of "compiler" is not attached to Python (the language), but is attached to the implementation. @+ MCI Well the pyc, which I thought was the Python bytecode, is then interpreted by the VM. As Michel says, "to compile" is not always unambiguous. My definition includes a one-way transformation from human-readable source text into something that can be more efficiently interpreted by other code, or by hardware. The compiler really doesn't care whether the machine it's targeting is real or virtual. The CPython implementation of Python compiles the source text into a bytecode file, with extension .pyc.That certainly is a compilation step. Followed (much) later by an interpreted one. To pick a specific implementation of C++, Microsoft C++ compiles C++ source text into an "executable file," with extension .exe (I'm ignoring little details, like the linker). That's a compilation step. Then the exe file is (later) interpreted by the microcode on the Pentium chip. As far as I know, nobody has yet built a microcode implementation of a Python VM (Virtual Machine). Nor have I seen one for the Java VM. However, in the early 80's there was a microcode implementation of the P-system VM. It was never a commercial success, but it existed. And there have been at least three Forth machines, where the hardware itself was designed to support the language's VM. No microcode at all. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
On Thursday 30 July 2009, Wolfgang Rohdewald wrote: > so I did the conversion mentioned there. This works: I actually do not know if it works - but it compiles. -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
"Michel Claveau - MVP" writes: > Hi! > > > Python is interpreted > > No. Yes. The same Python code is both interpreted and compiled so as to run it. > Python is compiled (--> .pyc) The Python bytecode (the contents of the compiled ‘foo.pyc’ file) is then interpreted by the run-time Python interpreter, to actually run the program. -- \ “Value your freedom or you will lose it, teaches history. | `\ “Don't bother us with politics,” respond those who don't want | _o__) to learn.” —Richard Stallman, 2002 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Regexp problem
On 30 jul, 15:07, MRAB wrote: > Beldar wrote: > > Hi there! > > > I have a problem and i'm not very good at regular expressions. > > I have a text like "lalala lalala tiruri beldar-is-listening tiruri > > lalala" I need a regexp to get the 'beldar' part, the format is > > 'something-is-listening', i need to get the something part, use it in > > my code, and then replace the whole 'something-is-listening' for > > another string. > > \w+ will match a word and enclosing it in (...) will capture what was > matched: > > m = re.search(r"(\w+)-is-listening", text) > print "Captured '%s'" % m.group(1) > print "Matched from %d to %d" % (m.start(), m.end()) Ok, thank you all, it was very helpful! -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPDF and print restrictions
On Jul 27, 4:16 pm, Chris Curvey wrote: > Has anyone out there been able to enforce print restrictions on a PDF > document by usingPyPDF? The documentation for "encrypt" states: > > # @param user_pwd The "user password", which allows for opening and > reading > # the PDF file with the restrictions provided. > > But there is no parameter for providing a restriction, and I can't > find a reference to any kind of restriction besides this comment in > the docs. > > Thanks in advance! I found some (I think old-ish) documentation on encryption and permissions (of course, I've lost the link). I think there are additional permissions that have been implemented since the doc that I found, but this patch works for me. Index: C:/Documents and Settings/ccurvey/PyPDF/pyPdf/pdf.py === --- C:/Documents and Settings/ccurvey/PyPDF/pyPdf/pdf.py(revision 1) +++ C:/Documents and Settings/ccurvey/PyPDF/pyPdf/pdf.py(revision 2) @@ -118,7 +118,10 @@ # @param use_128bit Boolean argument as to whether to use 128bit # encryption. When false, 40bit encryption will be used. By default, this # flag is on. -def encrypt(self, user_pwd, owner_pwd = None, use_128bit = True): +# @param perm_mask bitmask of the permissions that should be granted. +# Defaults to -1, which is "everything permitted" +def encrypt(self, user_pwd, owner_pwd = None, use_128bit = True, +perm_mask=-1): import md5, time, random if owner_pwd == None: owner_pwd = user_pwd @@ -130,8 +133,8 @@ V = 1 rev = 2 keylen = 40 / 8 -# permit everything: -P = -1 + +P = perm_mask O = ByteStringObject(_alg33(owner_pwd, user_pwd, rev, keylen)) ID_1 = md5.new(repr(time.time())).digest() ID_2 = md5.new(repr(random.random())).digest() Index: C:/Documents and Settings/ccurvey/PyPDF/pyPdf/__init__.py === --- C:/Documents and Settings/ccurvey/PyPDF/pyPdf/__init__.py (revision 1) +++ C:/Documents and Settings/ccurvey/PyPDF/pyPdf/__init__.py (revision 2) @@ -1,2 +1,11 @@ from pdf import PdfFileReader, PdfFileWriter + +PERM_NONE = 0 +PERM_PRINT = 2 +PERM_MODIFY = 4 +PERM_COPY_TEXT = 8 +PERM_ANNOTATE = 16 + +PERM_ALL = PERM_PRINT | PERM_MODIFY | PERM_COPY_TEXT | PERM_ANNOTATE + __all__ = ["pdf"] -- http://mail.python.org/mailman/listinfo/python-list
Re: Regexp problem
On 7/30/2009 9:32 AM, Beldar wrote: On 30 jul, 15:07, MRAB wrote: Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'something-is-listening', i need to get the something part, use it in my code, and then replace the whole 'something-is-listening' for another string. \w+ will match a word and enclosing it in (...) will capture what was matched: m = re.search(r"(\w+)-is-listening", text) print "Captured '%s'" % m.group(1) print "Matched from %d to %d" % (m.start(), m.end()) Ok, thank you all, it was very helpful! Wow, I really need to learn more about regexp... Any tutorials you guys can recommend? Marcus -- http://mail.python.org/mailman/listinfo/python-list
Re: New implementation of re module
> MRAB (M) wrote: >M> Hi all, >M> I've been working on a new implementation of the re module. The details >M> are at http://bugs.python.org/issue2636, specifically from >M> http://bugs.python.org/issue2636#msg90954. I've included a .pyd file for >M> Python 2.6 on Windows if you want to try it out. >M> I'm interested in how fast it is generally, compared with the current re >M> module, but especially when faced with those 'pathological' regular >M> expressions which seem to take a long time to finish, for example: >M> re.search(r"^(.+|D)*A$", "x" * 25 + "B") >M> which on my PC (1.8GHz) takes 18.98secs with the re module but <0.01secs >M> with this new implementation. Is this version also going to use the Thompson approach? -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Dave Angel wrote: Ah yes, we thread on the territory of word definition and difference in interpretation. Any argument is doomed to fail if not agreed or at least taken in perspective of the terminology used by users. I could be (well it is quite likely) wrong in my interpretation of the terminology, but here goes it anyway: Machine Code: Whatever the machine executes, it could be that the CPU uses an abstraction of microcode to do this but from the perspective of the user, this is all done in the same 'black box' Compiling: Translate words/symbols/mnemonics to machine code, which than can be either loaded, linked and executed by an OS or read and executed by the BIOS. Interpreted: Instructions which can be fed to a previous compiled program that is able to dynamically change its execution and flow without the need to recompile itself. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Semaphore Techniques
> Carl Banks (CB) wrote: >CB> On Jul 29, 7:14 am, Piet van Oostrum wrote: >>> > Carl Banks (CB) wrote: >>> >CB> On Jul 28, 3:15 pm, John D Giotta wrote: >>> >>> I'm looking to run a process with a limit of 3 instances, but each >>> >>> execution is over a crontab interval. I've been investigating the >>> >>> threading module and using daemons to limit active thread objects, but >>> >>> I'm not very successful at grasping the documentation. >>> >>> >>> Is it possible to do what I'm trying to do and if so anyone know of a >>> >>> useful example to get started? >>> >CB> It seems like you want to limit the number of processes to three; the >>> >CB> threading module won't help you there because it deals with threads >>> >CB> within a single process. >>> >CB> What I'd do is to simply run the system ps to see how many processes >>> >CB> are running (ps is pretty versatile on most systems and can find >>> >CB> specifically targeted processes like you program), and exit if there >>> >CB> are already three. >>> >>> That will surely run into some race conditions. >CB> What, the OS might not have gotten around to update the process table >CB> to include a process started minutes ago? (He said he was starting >CB> the processes over crontab intervals, not that he communicated what he >CB> wanted well.) No but between the time you get the ps output and decide not to start a new process one of the processes might have exited. As I said it probably is not a big deal, but you (he) should be aware of it I think. The other possible race condition: two processes starting at approximately the same time and both not detecting the other will probably not occur because of the time distance between starting the processes by cron. Unless the system is so busy that ps takes a lng time. The problem is similar to the sleeping barber problem (3 sleeping barbers actually). -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: gamma approximation : what is module cmath and where is it located ?
[email protected] wrote: from cmath import * What is cmath, where did it come from and how does it differ from the standard math module ? Dave WB3DWE I saw the number 4 in silver, Guido (apologies to Wm Carlos Williams) I'm surprised that with all the responses, nobody has pointed out the dangers involved in using from cmath import * In general, this form of import is discouraged. I presume there's no problem if you're not also importing 'math' and all your calls are intending to be for the complex versions. But if you're mixing things up, consider using the more conventional import cmath and using cmath. as a prefix before the function calls. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: socket send
"NighterNet" wrote in message news:[email protected]... I am trying to figure out how to send text or byte in python 3.1. I am trying to send data to flash socket to get there. I am not sure how to work it. buff= 'id=' , self.id , ':balive=False\n' clientSock.send(buff); -- http://mail.python.org/mailman/listinfo/python-list Python 3.1 strings are Unicode (think characters not bytes). When writing to files, sockets, etc. bytes must be used. Unicode strings have an encode() method, where you can specify an appropriate encoding (ascii, latin-1, windows-1252, utf-8, etc.): clientSock.send(buff.encode('ascii')) When reading from the socket, you can decode() the byte strings back into Unicode strings. data = clientSock.recv(1024).decode('ascii') -Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: No PyPI search for 3.x compatible packages
On 30 Lug, 01:55, Neil Hodgson wrote: > There appears to be no way to search PyPI for packages that are > compatible with Python 3.x. There are classifiers for 'Programming > Language' including 'Programming Language :: Python :: 3' but that seems > to be for implementation language since there are so many packages that > specify C. There are a total of 109 packages classified with Python :: > [3, 3.0, 3.1] out of a total of 4829 > packages.http://pypi.python.org/pypi?:action=browse&show=all&c=214&c=533 > > The search box appears to search for any word entered so a search > like "xml 3.0" or "xml AND 3.0" does not help. > > Some packages include version information in the Py Version column of > their download lists or embedded in the download file names. Projects > are often constrained to a particular set of Python versions so need to > choose packages that will work with those versions. It would be helpful > if PyPI made this information more visible and searchable. > > Neil Are you sure? I note that for example pygtk has as language tags both C and python. So maybe a C extension for python3 would have both C and python 3 as language tags. I suspect that the 109 packages you found are the only ones obf the 4829 which works with python3 (but I hope to be wrong ). Ciao - FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Regexp problem
Marcus Wanner writes: > On 7/30/2009 9:32 AM, Beldar wrote: >> On 30 jul, 15:07, MRAB wrote: >>> Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'something-is-listening', i need to get the something part, use it in my code, and then replace the whole 'something-is-listening' for another string. >>> \w+ will match a word and enclosing it in (...) will capture what was >>> matched: >>> >>> m = re.search(r"(\w+)-is-listening", text) >>> print "Captured '%s'" % m.group(1) >>> print "Matched from %d to %d" % (m.start(), m.end()) >> >> Ok, thank you all, it was very helpful! > Wow, I really need to learn more about regexp... > Any tutorials you guys can recommend? I have to confess that after fiddling with regexps for quite a while with no great success, I learnt the hard (and best) way, i.e. using them to write something vile and horrible. [*] I commend this path to you also. ;-) Cheers, Peter [*] http://git.gpleda.org/?p=gaf.git;a=blob;f=libgeda/desktop-i18n;h=6fab9b85b -- Peter Brett Remote Sensing Research Group Surrey Space Centre -- http://mail.python.org/mailman/listinfo/python-list
Re: No PyPI search for 3.x compatible packages
2009/7/30 Francesco Bochicchio : > On 30 Lug, 01:55, Neil Hodgson wrote: >> There appears to be no way to search PyPI for packages that are >> compatible with Python 3.x. There are classifiers for 'Programming >> Language' including 'Programming Language :: Python :: 3' but that seems >> to be for implementation language since there are so many packages that >> specify C. There are a total of 109 packages classified with Python :: >> [3, 3.0, 3.1] out of a total of 4829 >> packages.http://pypi.python.org/pypi?:action=browse&show=all&c=214&c=533 >> >> The search box appears to search for any word entered so a search >> like "xml 3.0" or "xml AND 3.0" does not help. >> >> Some packages include version information in the Py Version column of >> their download lists or embedded in the download file names. Projects >> are often constrained to a particular set of Python versions so need to >> choose packages that will work with those versions. It would be helpful >> if PyPI made this information more visible and searchable. >> >> Neil > > Are you sure? I note that for example pygtk has as language tags both > C and python. So maybe a C extension > for python3 would have both C and python 3 as language tags. > > I suspect that the 109 packages you found are the only ones obf the > 4829 which works with python3 (but I hope > to be wrong ). Also, of course, they may not be the only ones that work, but merely the only ones where the author has checked they work and tagged the entry. It's quite possible that some packages will work unmodified... Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Martin P. Hellwig wrote: Dave Angel wrote: Ah yes, we thread on the territory of word definition and difference in interpretation. Any argument is doomed to fail if not agreed or at least taken in perspective of the terminology used by users. I could be (well it is quite likely) wrong in my interpretation of the terminology, but here goes it anyway: Machine Code: Whatever the machine executes, it could be that the CPU uses an abstraction of microcode to do this but from the perspective of the user, this is all done in the same 'black box' Compiling: Translate words/symbols/mnemonics to machine code, which than can be either loaded, linked and executed by an OS or read and executed by the BIOS. Interpreted: Instructions which can be fed to a previous compiled program that is able to dynamically change its execution and flow without the need to recompile itself. Depending on the level of understanding of the user, plus his history and his biases, he will include more or less in his "black box." In the old days, microcode was not "on-chip" but stored separately in control memory. And on many machines, it was changeable at will. To many users these days, the entire system including software is a black box, which gradually breaks down (gets slow, runs out of space, crashes a lot) and must be replaced. They don't distinguish operating system from application, real memory from virtual, or viruses from bugs. But of course those users wouldn't be participating in this discussion. My background includes specifying hardware instruction sets and architecture. And writing microcode for multiple machines. And writing parts of compilers, interpreters, assemblers, and so on. And microcoding interpreters. And hooking into compilers to modify how they would generate code. And hooking into runtimes to test running code in realtime. So I tend to have very flexible definition of compiler and interpreter. Probably the only reason I jumped in here was the unmentioned bias that somehow a compiler is superior to an interpreter. I think I'd better extend my definition of compilation. It's a step that's statically taken over a series of instructions (not necessarily text source), that transforms it into a form closer to the targeted enviromment, real or virtual. Most C++ compilers have two compilers operating serially, the first to turn the source code into an intermediate form (like byte code), and the second to generate what is commonly called "machine code." The second part of course is duplicated for each different target processor. So Java is compiled into byte code, and the typical java VM then compiles that piecewise into machine code (so called JIT compiling, for just in time). BTW, interpreters don't have to be written in a compiled language. Anyway, I don't object to your definitions. We all have different perspectives. DaveA -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyKook 0.0.2 - a simple build tool similar to Make or Ant
Hi,
I have released pyKook 0.0.2.
http://pypi.python.org/pypi/Kook/0.0.2
http://www.kuwata-lab.com/kook/
http://www.kuwata-lab.com/kook/pykook-users-guide.html
Overview
pyKook is a simple build tool similar to Make, Ant, Rake, or SCons.
pyKook regards software project as cooking.
Terms used in pyKook are cooking terms.
For example:
cookbook- Makefile
product - target file
ingredient - source file
recipe - how to create target from source
spices - command-line options for recipe
Cookbook (= Makefile) is written in pure Python.
You can write any statements or expressions in cookbook.
NOTICE: pyKook is under alpha release. Spec and features may be
changed
in the future without previous announcement.
Example
---
Example of cookbook (Kookbook.py):
--
##
## properties
##
cc = prop('cc', 'gcc')
cflags = prop('cflags', '-g -Wall')
##
## recipes
##
@ingreds("hello")
def task_all(c):
pass
@product("hello")
@ingreds("hello.o")
def file_command(c):
"""generates hello command"""
system(c%"$(cc) $(cflags) -o $(product) $(ingred)")
@product("*.o")
@ingreds("$(1).c", if_exists("$(1).h"))
def file_ext_o(c):
"""compile '*.c' and '*.h'"""
system(c%"$(cc) $(cflags) -c $(1).c")
def task_clean(c):
rm_f("*.o")
--
Exampe of result:
==
bash> ls
Kookbook.py hello.chello.h
bash> pykook -l
Properties:
cc : 'gcc'
cflags : '-g -Wall'
Task recipes:
all : cook all products
clean : remove by-products
File recipes:
hello : generates hello command
*.o : compile '*.c' and '*.h'
(Tips: you can set 'kook_default_product' variable in your
kookbook.)
bash> pykook all # or, pykook --cc=gcc4 all
### *** hello.o (func=file_ext_o)
$ gcc -g -Wall -c hello.c
### ** hello (func=file_command)
$ gcc -g -Wall -o hello hello.o
### * all (func=task_all)
==
See users-guide for more details.
http://www.kuwata-lab.com/kook/pykook-users-guide.html
Enhancements, Changes, Bug fixes sice 0.0.1
---
Enhancements:
- Python 3 support.
- Add 'kk' script which is shortcat for kk command.
Changes:
- Decorator '@cmdopts()' is renamed to '@spices()', and
there is no need to call parse_cmdopts().
### prev version
@cmdopts('-v: verbose', '-f file: filename')
def task_example(c, *args):
opts, rests = c.parse_cmdopts(args)
verbose = opts.get('v', False):
fileame = opts.get('f', None)
### since this release (0.0.2)
@spices('-v: verbose', '-f file: filename')
def task_example(c, *args, *kwargs):
opts, rests = kwarts, args
verbose = opts.get('v', False):
fileame = opts.get('f', None)
- Remove 'pyk' script
- Testing library is changed from Python's unittest library
into 'test/oktest.py'.
Bugfixes:
- glob2() now recognizes files on current directory.
Have fun!
--
regards,
makoto kuwata
--
http://mail.python.org/mailman/listinfo/python-list
Re: Very Strange Problem
On Wed, Jul 29, 2009 at 3:10 PM, Omer Khalid wrote: > Hi Dave, > > Thanks for your reply. I actually didn't cut and paste my code as it was > dispersed in different places, i typed the logic behind my code in the email > (and obiviously made some typos, indentations is some thing else) but my Please, do not do that. It's very difficult to debug code that hasn't been seen. The code you posted has numerous problems (that likely have nothing to do with your actual problem.) If you're going to post code, try to recreate the issue with a small runnable script. If you can't do that, as it sounds like it would be difficult in this case as your code is dispersed in different places, at least post the relevant portions of the actual code. Don't re-type. > real code does not have these problems as my application runs fine with out > errors... > > Except that the line where i want to update the value doesn't get updated > and no exception is thrown. What's surprising for me is that i am doing the > same thing in hundreds of places in my 3k+ line code but by some reason this > part doesn't work... > > As far as the global variables are concerned, i am using them in other > places too and didn't see any problems. > > I think some thing else is going on here as the statement above and below my > modified lines get executed. If the statements above and below that line(s) are executed, then that line is certainly being executed as well. Try introducing some additional print statements to verify your mental model of what's happening: # set it to 1 print jobs print jobs[index] print jobs[index]['v'] jobs[index]['v'] = 1 print jobs print jobs[index] print jobs[index]['v'] print "Set to 1" > Is there a way in Python to debug memory address or to see where in memory > this object is stored, and is there a lock on it or else? You are barking up the wrong tree. Somewhere in your code you're doing something silly that's causing your issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
On 2009-07-30, Dave Angel wrote: > Steven makes some good points. You have to define what level > of clever you're protecting from. A determined hacker will > get in no matter what you do, unless you want to ship the > program in a proprietary embedded system, encased in epoxy. That won't stop a dedicated reverse-engineering effort. It might take an X-ray machine, machine tools, various nasty chemicals, and quite a bit of skill and patience -- but it can be done. > Further, if you have an extension of .py or .pyc, a > knowledgeable hacker will know it's probably python. > > You imply you want it to run unmodifed on multiple unknown > Linux versions. I think that lets out binfmt solutions. That > means you need to test and support not only multiple Linux > implementations, but multiple Python versions, because who > knows what the user may have installed. I think you need to > rethink your support strategy. And maybe concentrate on being > able to detect change, rather than prevent it. Or even being able to benefit from change. :) -- Grant Edwards grante Yow! FROZEN ENTREES may at be flung by members of visi.comopposing SWANSON SECTS ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
"Martin P. Hellwig" writes: > Machine Code: > Whatever the machine executes, it could be that the CPU uses an > abstraction of microcode to do this but from the perspective of the > user, this is all done in the same 'black box' This requires, of course, defining what is the machine. Python bytecode targets a virtual machine that is implemented differently for each hardware platform. > Compiling: > Translate words/symbols/mnemonics to machine code, which than can be > either loaded, linked and executed by an OS or read and executed by > the BIOS. Related to the above point, the “machine code” can just as easily be codes for a virtual machine specification. This is the case for the bytecode instructions Python gets compiled to. > Interpreted: > Instructions which can be fed to a previous compiled program that is > able to dynamically change its execution and flow without the need to > recompile itself. This doesn't make much sense to me, I must say. I'd say, instead, that a program is interpreted if its instruction are dynamically translated to underlying platform instructions at execution time. This is the case for the bytecode instructions interpreted by the Python virtual machine. -- \ “Often, the surest way to convey misinformation is to tell the | `\ strict truth.” —Mark Twain, _Following the Equator_ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
On 2009-07-30, Martin P. Hellwig wrote: > Michel Claveau - MVP wrote: > >>> Python is interpreted >> >> No. Python is compiled (--> .pyc) >> But the term "to compile" is not always unambiguous... >> And the notion of "compiler" is not attached to Python (the >> language), but is attached to the implementation. > > Well the pyc, which I thought was the Python bytecode, It is, but that's just one particular implementation you're talking about (though by far the most widely used one). > is then interpreted by the VM. Yup. Just like .exe files are interpreted by the microcode in the processor that implements the IA32 VM. It would be quite possible to put a Python VM into hardware. Alternatevly, you can compiler Python into Java bytecode and run that "directly" on hardware. -- Grant Edwards grante Yow! It don't mean a at THING if you ain't got visi.comthat SWING!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Connecting multiple test cases in a sort of pipe
On Jul 30, 2:43 am, "Diez B. Roggisch" wrote: > Write a TestCase-subclass that simply works like this: > > class FileTests(TestCase): > > def test_create(self): > self.created_file = create() > assert something > > def test_list(self): > self.test_create() > delete(self.created_file) > > Passing state around is one of the reasons objects have been invented :) > And nobody ever said that you can't invoke a test-method from somewhere > else. Just to be clear, are you suggesting that these tests be run by a custom runnner rather than by the default runner from unittest? Thanks, Raghu -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
On 2009-07-30, Dave Angel wrote: > As far as I know, nobody has yet built a microcode implementation of a > Python VM (Virtual Machine). Nor have I seen one for the Java VM. Didn't Sun or somebody do one 10-12 years ago? Or did I misinterpret some press release or something? Off to google... > However, in the early 80's there was a microcode implementation of the > P-system VM. Ah yes. I remember sitting at an Intel MDS-80 "blue box" CP/M system entering assembly language by hand for a simple Pascal -> P-code compiler. IIRC, I typed it from a listing in the "Byte Big Book of Pascal". That machine was pretty high-tech, since I could save my work on an 8" floppy rather than a spool of paper tape. The floppy disks didn't leave big oil stains in your backpack! I got the compiler working, but I don't remember ever having a VM and run-time system. > It was never a commercial success, but it existed. And there > have been at least three Forth machines, where the hardware > itself was designed to support the language's VM. No > microcode at all. -- Grant Edwards grante Yow! When you get your at PH.D. will you get able to visi.comwork at BURGER KING? -- http://mail.python.org/mailman/listinfo/python-list
Use existing IE cookie
Hi there,
Relevant versions: Python 2.5, Vista Home, IE7
I am trying to scrape a website I have browsed manually in the past,
and also manually selected my options, and now want python to use my
existing cookie from the manual browse when downloading data.
Using: http://code.activestate.com/recipes/80443/ I have found the
"name" of the relevant cookie, just after reading urllib2 docs, I
can't see how to "send" or have my python instance use "MY" existing
cookie.
Using the following:
***
import re
import urllib2, cookielib
# set things up for cookies
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)
reply = urllib2.urlopen('foo.html').read()
print reply
***
This does return data, just default data, not the data from the
options I set up when manually browsing.
My sense is that I need "something" in the () part of
HTTPCookieProcessor() but I have no idea as to what... the docs say
"cookiejar" but the only code examples I have found are to create a
cookiejar for the existing Python session, not to use the cookies from
my prior manual meanderings.
Any help greatly appreciated.
--
http://mail.python.org/mailman/listinfo/python-list
RE: Run pyc file without specifying python path ?
Hi Dave, On second thoughts, I may have a problem implementing the wrapper solution, because my actual test_pyc.pyc, needs to parse its command line. Namely, the actual call to test_pyc.pyc looks something like this: $ python test_pyc.py -U dave -PpasswoRD -C CreateMcGroupOnVolume --SVMs_IPs '10.1.1.1 , 10.1.1.2' -n "host1,host2" -g gn -j jn -s svn -t tvn -p pool1 -l -c And I don't know of a way to add these parameters to the "import test_pyc" in wrapper Is there a way to pass information to an imported module ? (Sorry if there's an obvious answer, I just cannot figure it out). Bye, Ron. > -Original Message- > From: Dave Angel [mailto:[email protected]] > Sent: Thursday, July 30, 2009 16:03 > To: Barak, Ron > Cc: 'Dave Angel'; '[email protected]' > Subject: RE: Run pyc file without specifying python path ? > > Barak, Ron wrote: > >> -Original Message- > >> From: Dave Angel [mailto:[email protected]] > >> Sent: Wednesday, July 29, 2009 21:05 > >> To: Barak, Ron > >> Cc: '[email protected]' > >> Subject: Re: Run pyc file without specifying python path ? > >> > >> Barak, Ron wrote: > >> > >>> Hi, > >>> > >>> I wanted to make a python byte-code file executable, > >>> > >> expecting to be able to run it without specifying "python" on the > >> (Linux bash) command line. > >> > >>> So, I wrote the following: > >>> > >>> [r...@vmlinux1 python]# cat test_pyc.py #!/usr/bin/env python > >>> > >>> print "hello" > >>> [r...@vmlinux1 python]# > >>> > >>> and made its pyc file executable: > >>> > >>> [r...@vmlinux1 python]# ls -ls test_pyc.pyc > >>> 4 -rwxr-xr-x 1 root root 106 Jul 29 14:22 test_pyc.pyc > >>> [r...@vmlinux1 python]# > >>> > >>> So, I see: > >>> > >>> [r...@vmlinux1 python]# file test_pyc.py* > >>> test_pyc.py: a python script text executable > >>> test_pyc.pyc: python 2.3 byte-compiled > >>> [r...@vmlinux1 python]# > >>> > >>> If I try to do the following, no problem: > >>> > >>> [r...@vmlinux1 python]# python test_pyc.pyc hello > >>> [r...@vmlinux1 python]# > >>> > >>> However, the following fails: > >>> > >>> [r...@vmlinux1 python]# ./test_pyc.pyc > >>> -bash: ./test_pyc.pyc: cannot execute binary file > >>> [r...@vmlinux1 python]# > >>> > >>> Is there a way to run a pyc file without specifying the > >>> > >> python path ? > >> > >>> Bye, > >>> Ron. > >>> > >>> > >>> > >> I don't currently run Unix, but I think I know the problem. > >> > >> In a text file, the shell examines the first line, and if > it begins > >> #! > >> it's assumed to point to the executable of an interpreter for that > >> text file. Presumably the same trick doesn't work for a .pyc file. > >> > >> Why not write a trivial wrapper.py file, don't compile it, and let > >> that invoke the main code in the .pyc file? > >> > >> Then make wrapper.py executable, and you're ready to go. > >> > >> DaveA > >> > >> > >> > > > > Hi Dave, > > Your solution sort of defeats my intended purpose (sorry > for not divulging my 'hidden agenda'). > > I wanted my application to "hide" the fact that it's a > python script, and look as much as possible like it's a > compiled program. > > The reason I don't just give my user a py file, is that I > don't want a cleaver user to change the innards of the script. > > On the other hand, I don't want to make a compiled > (freezed?) version of the application, because it'll grow the > resulting file significantly, and I don't have the experience > to know how it will run on different Linuxes. > > Bye, > > Ron. > > > Most of the other answers basically paraphrased my suggestion > of making a wrapper file, not compiling it, and making it > executable. With that > approach, the user just types "wrapper.py" on his command line. > > And wrapper.py only needs two lines, a shebang, and an > import, no big deal if the user modifies it. The rest of > your code can be .pyc files. > > Steven makes some good points. You have to define what level > of clever you're protecting from. A determined hacker will > get in no matter what you do, unless you want to ship the > program in a proprietary embedded system, encased in epoxy. > Further, if you have an extension of .py or .pyc, a > knowledgeable hacker will know it's probably python. > > You imply you want it to run unmodifed on multiple unknown > Linux versions. I think that lets out binfmt solutions. > That means you need to test and support not only multiple > Linux implementations, but multiple Python versions, because > who knows what the user may have installed. I think you need > to rethink your support strategy. And maybe concentrate on > being able to detect change, rather than prevent it. > > DaveA > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Use existing IE cookie
KB wrote:
> Hi there,
>
> Relevant versions: Python 2.5, Vista Home, IE7
>
> I am trying to scrape a website I have browsed manually in the past,
> and also manually selected my options, and now want python to use my
> existing cookie from the manual browse when downloading data.
>
> Using: http://code.activestate.com/recipes/80443/ I have found the
> "name" of the relevant cookie, just after reading urllib2 docs, I
> can't see how to "send" or have my python instance use "MY" existing
> cookie.
>
> Using the following:
>
> ***
> import re
> import urllib2, cookielib
>
> # set things up for cookies
>
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
> urllib2.install_opener(opener)
>
> reply = urllib2.urlopen('foo.html').read()
>
> print reply
>
> ***
>
> This does return data, just default data, not the data from the
> options I set up when manually browsing.
>
> My sense is that I need "something" in the () part of
> HTTPCookieProcessor() but I have no idea as to what... the docs say
> "cookiejar" but the only code examples I have found are to create a
> cookiejar for the existing Python session, not to use the cookies from
> my prior manual meanderings.
Because this is a completely different beast. You need to find out if and
how to access IE-cookies from python - I guess some win32-road is to be
walked down for that.
Once you get a hold on them, you can build up whatever cookiejar urllib2
needs.
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
On 2009-07-30, Barak, Ron wrote: > Hi Dave, > > On second thoughts, I may have a problem implementing the > wrapper solution, because my actual test_pyc.pyc, needs to > parse its command line. Namely, the actual call to > test_pyc.pyc looks something like this: > > $ python test_pyc.py -U dave -PpasswoRD -C CreateMcGroupOnVolume --SVMs_IPs > '10.1.1.1 , 10.1.1.2' -n "host1,host2" -g gn -j jn -s svn -t tvn -p pool1 -l > -c > > And I don't know of a way to add these parameters to the > "import test_pyc" in wrapper > > Is there a way to pass information to an imported module ? > (Sorry if there's an obvious answer, I just cannot figure it > out). I don't understand your problem. The module would parse sys.argv just like always. If you don't like that for some reason, you could define an entry point in the module and call it: #!/usr/bin/python import sys,test_pyc test_pyc.main(*sys.argv) -- Grant Edwards grante Yow! We just joined the at civil hair patrol! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Use existing IE cookie
> > Using:http://code.activestate.com/recipes/80443/ > Thanks for the prompt reply, Diez! Using the above I have found the name of the cookie (I did google how to use IE cookies in python and that was the best match) but it only tells me the name of the cookie, not how to use it. Any clues? TIA! -- http://mail.python.org/mailman/listinfo/python-list
Help with Regex for domain names
I'm trying to figure out how to write efficiently write a regex for domain names with a particular top level domain. Let's say, I want to grab all domain names with country codes .us, .au, and .de. I could create three different regexs that would work: regex = re.compile(r'[\w\-\.]+\.us) regex = re.compile(r'[\w\-\.]+\.au) regex = re.compile(r'[\w\-\.]+\.de) How would I write one to accommodate all three, or, better yet, to accommodate a list of them that I can pass into a method call? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Ben Finney wrote: "Martin P. Hellwig" writes: Machine Code: Whatever the machine executes, it could be that the CPU uses an abstraction of microcode to do this but from the perspective of the user, this is all done in the same 'black box' This requires, of course, defining what is the machine. Python bytecode targets a virtual machine that is implemented differently for each hardware platform. I would further define 'black box' as the hardware a kernel programmer writes to. Interpreted: Instructions which can be fed to a previous compiled program that is able to dynamically change its execution and flow without the need to recompile itself. This doesn't make much sense to me, I must say. I'd say, instead, that a program is interpreted if its instruction are dynamically translated to underlying platform instructions at execution time. This is the case for the bytecode instructions interpreted by the Python virtual machine. Yes that is indeed a much better description, I'll steal that from you :-) -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Use existing IE cookie
KB wrote: > >> > Using:http://code.activestate.com/recipes/80443/ >> > > Thanks for the prompt reply, Diez! Using the above I have found the > name of the cookie (I did google how to use IE cookies in python and > that was the best match) but it only tells me the name of the cookie, > not how to use it. Ah, sorry, should have read the recipe also. For me it looks as if findIECookie from that recipe is to be called with the name. Then it should return the value, or None What does you full example look like, including the cookie-acquisition-stuff? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Dave Angel wrote: [snip] As far as I know, nobody has yet built a microcode implementation of a Python VM (Virtual Machine). Nor have I seen one for the Java VM. However, in the early 80's there was a microcode implementation of the P-system VM. It was never a commercial success, but it existed. And there have been at least three Forth machines, where the hardware itself was designed to support the language's VM. No microcode at all. There's Jazelle: http://en.wikipedia.org/wiki/Jazelle. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
Ben Finney wrote: "Martin P. Hellwig" writes: Machine Code: Whatever the machine executes, it could be that the CPU uses an abstraction of microcode to do this but from the perspective of the user, this is all done in the same 'black box' This requires, of course, defining what is the machine. Python bytecode targets a virtual machine that is implemented differently for each hardware platform. Compiling: Translate words/symbols/mnemonics to machine code, which than can be either loaded, linked and executed by an OS or read and executed by the BIOS. Related to the above point, the “machine code” can just as easily be codes for a virtual machine specification. This is the case for the bytecode instructions Python gets compiled to. Interpreted: Instructions which can be fed to a previous compiled program that is able to dynamically change its execution and flow without the need to recompile itself. This doesn't make much sense to me, I must say. I'd say, instead, that a program is interpreted if its instruction are dynamically translated to underlying platform instructions at execution time. This is the case for the bytecode instructions interpreted by the Python virtual machine. Interpretation doesn't necessarily mean translating to machine code at execution time. What you're describing is more like JIT. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with Regex for domain names
Feyo wrote: > I'm trying to figure out how to write efficiently write a regex for > domain names with a particular top level domain. Let's say, I want to > grab all domain names with country codes .us, .au, and .de. > > I could create three different regexs that would work: > regex = re.compile(r'[\w\-\.]+\.us) > regex = re.compile(r'[\w\-\.]+\.au) > regex = re.compile(r'[\w\-\.]+\.de) > > How would I write one to accommodate all three, or, better yet, to > accommodate a list of them that I can pass into a method call? Thanks! Just a point of interest: A correctly formed domain name may have a trailing period at the end of the TLD [1]. Example: foo.bar.com. Though you do not often see this, it's worth accommodating "just in case"... [1] http://homepages.tesco.net/J.deBoynePollard/FGA/web-fully-qualified-domain-name.html -- Tim Daneliuk [email protected] PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with Regex for domain names
Feyo wrote: I'm trying to figure out how to write efficiently write a regex for domain names with a particular top level domain. Let's say, I want to grab all domain names with country codes .us, .au, and .de. I could create three different regexs that would work: regex = re.compile(r'[\w\-\.]+\.us) regex = re.compile(r'[\w\-\.]+\.au) regex = re.compile(r'[\w\-\.]+\.de) How would I write one to accommodate all three, or, better yet, to accommodate a list of them that I can pass into a method call? Thanks! > regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)') If you have a list of country codes ["us", "au", "de"] then you can build the regular expression from it: regex = re.compile(r'[\w\-\.]+\.(?:%s)' % '|'.join(domains)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Use existing IE cookie
> What does you full example look like, including the
> cookie-acquisition-stuff?
>
> Diez
I ran them seperately, hoping for a clue as to what my "cookiejar"
was.
The cookie-acquisition stuff returns "screener.ashx?v=151" when I
search with my domain I am interested in. I have tried
urllib2.HTTPCookieProcessor('screener.ashx?v=151') but that failed
with attr has no cookie header.
>From the HTTPCookieProcessor doco, it appears that non-IE browsers
have a cookie file (and example code) but from what I can tell IE uses
a hidden folder. (you can set your location in IE but it appends a
folder "\Temporary Internet Files" -
From: http://docs.python.org/dev/library/cookielib.html
***
This example illustrates how to open a URL using your Netscape,
Mozilla, or Lynx cookies (assumes Unix/Netscape convention for
location of the cookies file):
import os, cookielib, urllib2
cj = cookielib.MozillaCookieJar()
cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("http://example.com/";)
***
Not sure how to adapt this for IE.
--
http://mail.python.org/mailman/listinfo/python-list
Re: socket send
On Jul 30, 6:56 am, "Mark Tolonen" wrote: > "NighterNet" wrote in message > > news:[email protected]... > > >I am trying to figure out how to send text or byte in python3.1. I am > > trying to send data to flashsocketto get there. I am not sure how to > > work it. > > > buff= 'id=' , self.id , ':balive=False\n' > > clientSock.send(buff); > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Python3.1strings are Unicode (think characters not bytes). When writing > to files, sockets, etc. bytes must be used. Unicode strings have an > encode() method, where you can specify an appropriate encoding (ascii, > latin-1, windows-1252, utf-8, etc.): > > clientSock.send(buff.encode('ascii')) > > When reading from thesocket, you can decode() the byte strings back into > Unicode strings. > > data = clientSock.recv(1024).decode('ascii') > > -Mark I am not sure how to use struct package. Here an example for the input: {id:1,playername:guest,x:100,y:50} {id:2,playername:tester,x:100,y:50} struct.pack(? ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
Some have treated this as a troll. I don't.
r wrote:
[snip]
1.) No need to use "()" to call a function with no arguments.
Python --> "obj.m2().m3()" --ugly
Ruby --> "obj.m1.m2.m3" -- sweeet!
Man, i must admit i really like this, and your code will look so much
cleaner.
+1
2.) the .each method
container.each{|localVar| block}
This method can really cleanup some ugly for loops, although i really
like the readability of for loops.
Not clear.
3.) true OOP
Now before you go and get all "huffy" over this statement, hear me
out. Python is the best language in the world. But it damn sure has
some warts! "len(this)" instead of "obj.length" max(that) instead of
[1,2,3,4,5].max(). You know what i am talking about here people. We
all get complacent and It seems easier to just cope with these
problems instead of fighting for change. But look at the French, WHAT
THE HELL HAS THAT DONE FOR THEM, *NOTHING*
+0.6
or better [1, 2, 3, 4, 5].len or [1, 2, 3, 4, 5].max
What has this got to do with "true OOP"?
[snip]
--
http://mail.python.org/mailman/listinfo/python-list
Re: Use existing IE cookie
KB wrote:
>
>> What does you full example look like, including the
>> cookie-acquisition-stuff?
>>
>> Diez
>
> I ran them seperately, hoping for a clue as to what my "cookiejar"
> was.
>
> The cookie-acquisition stuff returns "screener.ashx?v=151" when I
> search with my domain I am interested in. I have tried
> urllib2.HTTPCookieProcessor('screener.ashx?v=151') but that failed
> with attr has no cookie header.
>
> From the HTTPCookieProcessor doco, it appears that non-IE browsers
> have a cookie file (and example code) but from what I can tell IE uses
> a hidden folder. (you can set your location in IE but it appends a
> folder "\Temporary Internet Files" -
>
> From: http://docs.python.org/dev/library/cookielib.html
>
> ***
> This example illustrates how to open a URL using your Netscape,
> Mozilla, or Lynx cookies (assumes Unix/Netscape convention for
> location of the cookies file):
>
> import os, cookielib, urllib2
> cj = cookielib.MozillaCookieJar()
> cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> r = opener.open("http://example.com/";)
> ***
>
> Not sure how to adapt this for IE.
You could create a file that resembles the cookies.txt - no idea how that
looks, but I guess it's pretty simple.
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On Jul 29, 9:06 pm, r wrote: > 1.) No need to use "()" to call a function with no arguments. > Python --> "obj.m2().m3()" --ugly > Ruby --> "obj.m1.m2.m3" -- sweeet! > Man, i must admit i really like this, and your code will look so much > cleaner. I personally would not prefer this, and would likely continue to use (), precisely for code clarity - let me explain: foo.nextval foo.val foo.previousval Which of the calls above referenced instance variables, and which ones called functions which changed the internal state of foo? I would have trouble saying, just based on the calls above. I would have to go back to the definition or documentation of foo to identify which is doing what. On the other hand, the following gives a better clue as to what is happening (granted not perfect, but better): foo.nextval() foo.val foo.previousval() ~G -- http://mail.python.org/mailman/listinfo/python-list
Re: Use existing IE cookie
On Jul 30, 9:23 am, "Diez B. Roggisch" wrote:
> KB wrote:
>
> >> What does you full example look like, including the
> >> cookie-acquisition-stuff?
>
> >> Diez
>
> > I ran them seperately, hoping for a clue as to what my "cookiejar"
> > was.
>
> > The cookie-acquisition stuff returns "screener.ashx?v=151" when I
> > search with my domain I am interested in. I have tried
> > urllib2.HTTPCookieProcessor('screener.ashx?v=151') but that failed
> > with attr has no cookie header.
>
> > From the HTTPCookieProcessor doco, it appears that non-IE browsers
> > have a cookie file (and example code) but from what I can tell IE uses
> > a hidden folder. (you can set your location in IE but it appends a
> > folder "\Temporary Internet Files" -
>
> > From:http://docs.python.org/dev/library/cookielib.html
>
> > ***
> > This example illustrates how to open a URL using your Netscape,
> > Mozilla, or Lynx cookies (assumes Unix/Netscape convention for
> > location of the cookies file):
>
> > import os, cookielib, urllib2
> > cj = cookielib.MozillaCookieJar()
> > cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
> > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> > r = opener.open("http://example.com/";)
> > ***
>
> > Not sure how to adapt this for IE.
>
> You could create a file that resembles the cookies.txt - no idea how that
> looks, but I guess it's pretty simple.
>
> Diez- Hide quoted text -
>
> - Show quoted text -
Yeah unfortunately I just tried Firefox and it uses cookies.sqlite
now... more dead ends :)
--
http://mail.python.org/mailman/listinfo/python-list
ANN: Leo 4.6.1 final released
Leo 4.6.1 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html Leo 4.6.1 fixes several minor bugs in Leo 4.6. The highlights of Leo 4.6 -- - Cached external files *greatly* reduces the time to load .leo files. - Leo now features a modern Qt interface by default. Leo's legacy Tk interface can also be used. - New --config, --file and --gui command-line options. - Leo tests syntax of .py files when saving them. - Leo can now open any kind of file into @edit nodes. - @auto-rst nodes allow easy editing of reStructuredText files. - Properties of commanders, positions and nodes simplify programming. - Improved Leo's unit testing framework. - Leo now requires Python 2.5 or later. - Dozens of small improvements and bug fixes. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Forum:http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [email protected] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On Jul 30, 12:04 am, alex23 wrote: > On Jul 30, 1:06 pm, r wrote: > > > 1.) No need to use "()" to call a function with no arguments. > > Python --> "obj.m2().m3()" --ugly > > Ruby --> "obj.m1.m2.m3" -- sweeet! > > Man, i must admit i really like this, and your code will look so much > > cleaner. > > How do you distinguish between calling a method with no arguments, and > getting access to the method object itself (because it _is_ an object, > y'know, it's OO all the way down...)? I agree with alex here. Will take the explicit syntax over the extra cognitive load of figuring out exactly what's going on with `obj.m1.m2.m3`. Python has its warts, but requiring ()'s on function calls isn't one of them. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: socket send
On 30 Lug, 18:06, NighterNet wrote: > On Jul 30, 6:56 am, "Mark Tolonen" wrote: > > > > > > > "NighterNet" wrote in message > > >news:[email protected]... > > > >I am trying to figure out how to send text or byte in python3.1. I am > > > trying to send data to flashsocketto get there. I am not sure how to > > > work it. > > > > buff= 'id=' , self.id , ':balive=False\n' > > > clientSock.send(buff); > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > > Python3.1strings are Unicode (think characters not bytes). When writing > > to files, sockets, etc. bytes must be used. Unicode strings have an > > encode() method, where you can specify an appropriate encoding (ascii, > > latin-1, windows-1252, utf-8, etc.): > > > clientSock.send(buff.encode('ascii')) > > > When reading from thesocket, you can decode() the byte strings back into > > Unicode strings. > > > data = clientSock.recv(1024).decode('ascii') > > > -Mark > > I am not sure how to use struct package. > Here an example for the input: > {id:1,playername:guest,x:100,y:50} > {id:2,playername:tester,x:100,y:50} > > struct.pack(? ) If your messages are ASCII, like it seems, forget about struct, which is for 'binary' message format. Format the string as you would in 2.6 ( using % or string.format for instance ) and then use encode as instructed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Run pyc file without specifying python path ?
Barak, Ron wrote: Hi Dave, On second thoughts, I may have a problem implementing the wrapper solution, because my actual test_pyc.pyc, needs to parse its command line. Namely, the actual call to test_pyc.pyc looks something like this: $ python test_pyc.py -U dave -PpasswoRD -C CreateMcGroupOnVolume --SVMs_IPs '10.1.1.1 , 10.1.1.2' -n "host1,host2" -g gn -j jn -s svn -t tvn -p pool1 -l -c And I don't know of a way to add these parameters to the "import test_pyc" in wrapper Is there a way to pass information to an imported module ? (Sorry if there's an obvious answer, I just cannot figure it out). Bye, Ron. -Original Message- From: Dave Angel [mailto:[email protected]] Sent: Thursday, July 30, 2009 16:03 To: Barak, Ron Cc: 'Dave Angel'; '[email protected]' Subject: RE: Run pyc file without specifying python path ? Barak, Ron wrote: -Original Message- From: Dave Angel [mailto:[email protected]] Sent: Wednesday, July 29, 2009 21:05 To: Barak, Ron Cc: '[email protected]' Subject: Re: Run pyc file without specifying python path ? Barak, Ron wrote: Hi, I wanted to make a python byte-code file executable, expecting to be able to run it without specifying "python" on the (Linux bash) command line. So, I wrote the following: [r...@vmlinux1 python]# cat test_pyc.py #!/usr/bin/env python print "hello" [r...@vmlinux1 python]# and made its pyc file executable: [r...@vmlinux1 python]# ls -ls test_pyc.pyc 4 -rwxr-xr-x 1 root root 106 Jul 29 14:22 test_pyc.pyc [r...@vmlinux1 python]# So, I see: [r...@vmlinux1 python]# file test_pyc.py* test_pyc.py: a python script text executable test_pyc.pyc: python 2.3 byte-compiled [r...@vmlinux1 python]# If I try to do the following, no problem: [r...@vmlinux1 python]# python test_pyc.pyc hello [r...@vmlinux1 python]# However, the following fails: [r...@vmlinux1 python]# ./test_pyc.pyc -bash: ./test_pyc.pyc: cannot execute binary file [r...@vmlinux1 python]# Is there a way to run a pyc file without specifying the python path ? Bye, Ron. I don't currently run Unix, but I think I know the problem. In a text file, the shell examines the first line, and if it begins #! it's assumed to point to the executable of an interpreter for that text file. Presumably the same trick doesn't work for a .pyc file. Why not write a trivial wrapper.py file, don't compile it, and let that invoke the main code in the .pyc file? Then make wrapper.py executable, and you're ready to go. DaveA Hi Dave, Your solution sort of defeats my intended purpose (sorry for not divulging my 'hidden agenda'). I wanted my application to "hide" the fact that it's a python script, and look as much as possible like it's a compiled program. The reason I don't just give my user a py file, is that I don't want a cleaver user to change the innards of the script. On the other hand, I don't want to make a compiled (freezed?) version of the application, because it'll grow the resulting file significantly, and I don't have the experience to know how it will run on different Linuxes. Bye, Ron. Most of the other answers basically paraphrased my suggestion of making a wrapper file, not compiling it, and making it executable. With that approach, the user just types "wrapper.py" on his command line. And wrapper.py only needs two lines, a shebang, and an import, no big deal if the user modifies it. The rest of your code can be .pyc files. Steven makes some good points. You have to define what level of clever you're protecting from. A determined hacker will get in no matter what you do, unless you want to ship the program in a proprietary embedded system, encased in epoxy. Further, if you have an extension of .py or .pyc, a knowledgeable hacker will know it's probably python. You imply you want it to run unmodifed on multiple unknown Linux versions. I think that lets out binfmt solutions. That means you need to test and support not only multiple Linux implementations, but multiple Python versions, because who knows what the user may have installed. I think you need to rethink your support strategy. And maybe concentrate on being able to detect change, rather than prevent it. DaveA (Please don't top-post. It puts responses out of order) You don't have to do anything special. Any module can import sys, and parse sys.argv, as long as it wasn't yet modified. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On Jul 30, 11:31 am, Falcolas wrote: > On Jul 29, 9:06 pm, r wrote: > > > 1.) No need to use "()" to call a function with no arguments. > > Python --> "obj.m2().m3()" --ugly > > Ruby --> "obj.m1.m2.m3" -- sweeet! > > Man, i must admit i really like this, and your code will look so much > > cleaner. > > I personally would not prefer this, and would likely continue to use > (), precisely for code clarity - let me explain: > > foo.nextval > foo.val > foo.previousval > > Which of the calls above referenced instance variables, and which ones > called functions which changed the internal state of foo? I would have > trouble saying, just based on the calls above. I would have to go back > to the definition or documentation of foo to identify which is doing > what. On the other hand, the following gives a better clue as to what > is happening (granted not perfect, but better): > > foo.nextval() > foo.val > foo.previousval() > > ~G I held your exact same view before i learned the Ruby language. And your veiw makes some good points, however, naming conventions with eliminate this problem all together. All "method names" should use the underscore to separate words, "variable names" should use camelCase, "constants" in all caps, and "class defs" in titlecase. def go_and_do_this_for_me_now(self, *args) self.variableNameHere MyClassNameHere THISISACONSTANT -or- THIS_IS_A_CONSTANT in your example i would have used the following foo.next_value foo.value foo.prev_value good naming conventions will make your life (and everybody else's) much easier when debugging code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On 30 Jul 2009, at 18:31 , Falcolas wrote: On Jul 29, 9:06 pm, r wrote: 1.) No need to use "()" to call a function with no arguments. Python --> "obj.m2().m3()" --ugly Ruby --> "obj.m1.m2.m3" -- sweeet! Man, i must admit i really like this, and your code will look so much cleaner. I personally would not prefer this, and would likely continue to use (), precisely for code clarity - let me explain: foo.nextval foo.val foo.previousval Which of the calls above referenced instance variables Well, that's very simple: none of them. In Ruby (as in Smalltalk), public instance variables simply don't exist. and which ones called functions which changed the internal state of foo? That you can't say, but neither can you say in Python as they could all be properties. And of course just because it's a method doesn't mean it mutates the object. I would have trouble saying, just based on the calls above. I would have to go back to the definition or documentation of foo to identify which is doing what. On the other hand, the following gives a better clue as to what is happening (granted not perfect, but better): Well... it doesn't give much of a clue no really. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On 30 Jul 2009, at 19:01 , Inky 788 wrote: On Jul 30, 12:04 am, alex23 wrote: On Jul 30, 1:06 pm, r wrote: 1.) No need to use "()" to call a function with no arguments. Python --> "obj.m2().m3()" --ugly Ruby --> "obj.m1.m2.m3" -- sweeet! Man, i must admit i really like this, and your code will look so much cleaner. How do you distinguish between calling a method with no arguments, and getting access to the method object itself (because it _is_ an object, y'know, it's OO all the way down...)? I agree with alex here. Will take the explicit syntax over the extra cognitive load of figuring out exactly what's going on with `obj.m1.m2.m3`. There's no cognitive load whatsoever: it's calling methods. Always. Ruby simply gives you no other option. Now it could be very simple methods to instance attributes, akin to a java getter, but it's still only methods. Furthermore Ruby has a pretty nice convention (sadly not used enough I think) taken from Scheme where it's possible to postfix a method name with "!" (note: the "!" is part of the name, there's no magic) to indicate that this method modifies the object it's called on rather than simply returning stuff. -- http://mail.python.org/mailman/listinfo/python-list
NASA using Python / Django for NEBULA (cloud comp.)
Hello Python devs! I'm supporting NASA on their NEBULA project and they're looking for Python / Django experts to join their team here in Mountain View, CA. If you're interested, let me know and we can talk more on how they're using Django in their environment! Thanks, Mehdi -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyplot
On 2009-07-30 04:02, Kaan AKŞİT wrote: I am a newbee in Python. I have some problem with usage of Pyplot. I have a loop that creates plot in every end of it. Problem starts here: The first plot is fine but the second one is plotted onto the first plot. I use: plt.cla() plt.draw() plt.hold(False) plt.close() plt.clf() but nothing works. Perhaps I am having a problem with basics, please help me if you know something about it. Create a new window by using figure(). You will want to ask matplotlib questions on the matplotlib mailing list: https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with Regex for domain names
On Jul 30, 11:56 am, MRAB wrote: > Feyo wrote: > > I'm trying to figure out how to write efficiently write a regex for > > domain names with a particular top level domain. Let's say, I want to > > grab all domain names with country codes .us, .au, and .de. > > > I could create three different regexs that would work: > > regex = re.compile(r'[\w\-\.]+\.us) > > regex = re.compile(r'[\w\-\.]+\.au) > > regex = re.compile(r'[\w\-\.]+\.de) > > > How would I write one to accommodate all three, or, better yet, to > > accommodate a list of them that I can pass into a method call? Thanks! > > > > regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)') > > If you have a list of country codes ["us", "au", "de"] then you can > build the regular expression from it: > > regex = re.compile(r'[\w\-\.]+\.(?:%s)' % '|'.join(domains)) Perfect! Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confessions of a Python fanboy
On Jul 30, 12:15 pm, Masklinn wrote: [snip] > Furthermore Ruby has a pretty nice convention (sadly not used enough I > think) taken from Scheme where it's possible to postfix a method name > with "!" (note: the "!" is part of the name, there's no magic) to > indicate that this method modifies the object it's called on rather > than simply returning stuff. Another oddity i did not like at first but must admit is growing on me vector.reverse --> returns a new reversed vector vector.reverse! --> modifies the instance vector in-place Of course in python you would do... vector.reverse --> in-place vector.reversed --> in-place The above example works pretty good, but this doesn't always "sound" good. Take for example this... point3d.offset --> return a new pt point3d.offseted --> What did you say!?!?! Now try Ruby's way point3d.offset! point3d.offset a symbol works better for these things -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with Regex for domain names
On Jul 30, 9:56 am, MRAB wrote: > Feyo wrote: > > I'm trying to figure out how to write efficiently write a regex for > > domain names with a particular top level domain. Let's say, I want to > > grab all domain names with country codes .us, .au, and .de. > > > I could create three different regexs that would work: > > regex = re.compile(r'[\w\-\.]+\.us) > > regex = re.compile(r'[\w\-\.]+\.au) > > regex = re.compile(r'[\w\-\.]+\.de) > > > How would I write one to accommodate all three, or, better yet, to > > accommodate a list of them that I can pass into a method call? Thanks! > > > > regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)') You might also want to consider that some country codes such as "co" for Columbia might match more than you want, for example: re.match(r'[\w\-\.]+\.(?:us|au|de|co)', 'foo.boo.com') will match. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does python have the capability for driver development ?
MalC0de wrote: > please introduce me some resource for system programming, I know that > python is very well at system programming level. > thanks Although it is possible (as others have said) to embed Python the interpreter into a driver, no one has done that that I know of. You'd have to write the driver in C or C++, though, and then provide embed a python interpreter and then provide a python interface (wrapper code written in C++) that would expose binary primitives and structures to python that the OS and driver use. Sounds like quite an undertaking. I embedded a python interpreter in a gina dll once (to write login code in python). That's a form of system programming, but not what you're asking about. Someone years ago someone embedded the perl interpreter into a Linux driver allowing some kinds of device drivers to be written in perl. It was made more as a curiosity though. Python is not well-suited to system programming. It takes extra work (via the ctypes library or other wrappers) to interface with C structs, plus calls all have to be marshalled to and from the native C APIs. Might be cool, though. System programming in Win32 is very complicated and messy. What little system programming I've done in Linux was a dream compared. Definitely you'll have to master win32 system programming in C and C++ before you try to embed python in anything. I'm sure there are a number of books on the subject. That's where I'd start. -- http://mail.python.org/mailman/listinfo/python-list
