Re: regex doubts

2008-07-21 Thread Fredrik Lundh

John Machin wrote:


'\n' is an "other character".


so how does a user enter that character?


Perhaps you could explain what you mean by "$ does the right thing".


wtf is wrong with you?



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Fredrik Lundh

Michael Torrie wrote:


[EMAIL PROTECTED] wrote:



I'm not dissing Python, here. Just noting that, if it is written in C,
that throws a curve at me in trying to balance the value of learning
Python vs. some other major language.


Definitely one of the most non-sequitor statements I have ever heard.
Actually your entire post doesn't make much sense.  Maybe you are a
brother bot to castropini?


or that perl troll making another attempt to add noise to this 
newsgroup?  I'm a bit surprised that he managed to generate this

many replies, really.



--
http://mail.python.org/mailman/listinfo/python-list


Re: Web Server

2008-07-21 Thread Fredrik Lundh

James Tanis wrote:

there's also apache, of course, and a bunch of others, including several 
Python solutions (more or less pre-packaged).  but the "open up" part 
still sounds a bit risky.  maybe you could turn things around, and let 
the application "push" data to your server instead?


Either way requires an open port, otherwise there's no way to negotiate new
clients.


The scenario I had in mind was rather to make his application the client 
for an external server, instead of using some external client to connect 
to someone's PC over HTTPS.  That wouldn't need an open server port on 
the client; any Comet-style protocol would work.


But at this point, only the OP knows enough about his application to be 
able to figure out if that's a usable approach.




--
http://mail.python.org/mailman/listinfo/python-list


Re: running a script with an input file

2008-07-21 Thread Fredrik Lundh

David Bikard wrote:

I'd like to run a program  so that it reads the input() or raw_input() 
statements from an input file instead of
reading from keyboard. I'd also like it to write the print statements in 
an output file rather than on the screen.


I'm on windows XP and when I run:

>

prog_name.py input_file output_file

I get an EOF error.

What should I do to make this work?


Was that supposed to be

   prog_name.py output_file

?  (< and > does i/o redirection; random google link:

   http://www.ss64.com/ntsyntax/redirection.html

If you want to do the same thing from inside the program, you can do:

   import sys

   sys.stdin = open("input_file")
   sys.stdout = open("output_file", "w")

before you start reading or writing stuff.



--
http://mail.python.org/mailman/listinfo/python-list


Please recommend a RPC system working with twisted.

2008-07-21 Thread 一首诗
Hi all,

I'm looking for an RPC system working with twisted.

1. Binary.  I want it run faster than any xml based RPC.

2. Bidirectional.  Unlike  HTTP, on which the client has to poll the
sever for events, the server should "call" the client's method to
notify events.

3. C/Python support.  Part of the system shall be written in C.

4. Could easily integrated  with twisted.

Unfortunately, there seems no such resolution existed.  So maybe I
have to give up some requirements.

---

It would be wonderful if ICE could integrate with twisted!
--
http://mail.python.org/mailman/listinfo/python-list


Python game programming challenge, NUMBER 7, in September!

2008-07-21 Thread richard
The date for the SEVENTH bi-annual PyWeek challenge has been set: Sunday 7th 
September to Sunday 14th September (00:00UTC to 00:00UTC).

  http://pyweek.org/

The PyWeek challenge invites entrants to write a game in one week from
scratch either as an individual or in a team. Entries must be developed
in Python, during the challenge, and must incorporate some theme chosen
at the start of the challenge.


REGISTRATION IS NOT YET OPEN --

In order to reduce the number of unnecessary registrations, we will open
the challenge for registration one month before the start date. See the
competition timetable and rules:

   http://www.pyweek.org/


PLANNING FOR THE CHALLENGE --

Make sure you have working versions of the libraries you're going to use.
The rules page has a list of libraries and other resources.

Make sure you know how to build an MD5 sum for your submission. See the
challenge help page for more information.

Make sure you can build packages to submit as your final submission (if
you're going to use py2exe, make sure you know how to use it and that it
works).

If you don't have access to Linux, Windows or a Mac to test on, contact
friends, family or other competitors to find someone who is able to test
for you.



-- 
Visit the PyWeek website:
  http://www.pyweek.org/
--
http://mail.python.org/mailman/listinfo/python-list


Python Written in C?

2008-07-21 Thread Peter Anderson
> Bah, new-fangled languages like Pascal... Real programmers write 
Fortran. Using punch-cards and paper-tape. Real programmers can edit 
their programs with a pointy stick and some home-made sticky-tape. -- 
Grant Edwards


Reminds me of a funny story from my past working life. I had this fibre 
tipped pen, given to me as a freebie by some computer company. The pen 
had something like "Floppy Disk Pen" printed down the barrel. A 
colleague who was more into IT management than programming or hands-on 
support picked it up at a meeting and said something like - "That's 
interesting, what's it for?" Seeing an opportunity I replied "Its a new 
bit of technology that allows you to write directly to your floppy disks 
when you are away from your computer!" "What a great idea!" he replied 
in all seriousness!


Maybe our friend could find one to code C# with! ;-)

Peter
--

Peter Anderson

There is nothing more difficult to take in hand, more perilous to 
conduct, or more uncertain in its success, than to take the lead in the 
introduction of a new order of things — Niccolo Machiavelli, /The 
Prince/, ch. 6


--
http://mail.python.org/mailman/listinfo/python-list


Re: regex doubts

2008-07-21 Thread Fredrik Lundh



Perhaps you could explain what you mean by "$ does the right thing".


wtf is wrong with you?


(I mean, you do know under what circumstances $ matches a newline 
character when used without modifiers, right?  So why do you keep 
behaving like a reddit commenter?)


--
http://mail.python.org/mailman/listinfo/python-list


What is the role of python2.6 and C++?

2008-07-21 Thread 甜瓜
Howdy,

I'm confused about the motivation of releasing python2.6 and python3.0
at the *same* time. IMO, 2.6 should be compatible with 2.5 while 3.0
is new style python. Currenly, most python projects works fine in 2.5.
When 3.0 becomes final release, those projects will be gradually moved
to 3.0. But even without the intermediate version 2.6, project
transformation with be smooth enough, and then 2.5, 2.6 will be
replaced by 3.0. I will not spend any time on studying 2.6. So why
does python development team put many efforts on 2.6? What is the role
of 2.6?

Another question is about the future of C++. I am a C++ programmer.
Since I studied python, most of my projects becomes written in python
because of the better and simpler OOP representation. As a supplement,
I use python C extension for computational extensive jobs. Therefore,
for a relatively long time, I do not use C++ any more... Anyone is
same to me? What is your attitude to the role of C++ in the age of
python?

Best regards,

--
ShenLei
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the role of python2.6 and C++?

2008-07-21 Thread cokofreedom
On Jul 21, 10:17 am, "甜瓜" <[EMAIL PROTECTED]> wrote:
> Howdy,
>
> I'm confused about the motivation of releasing python2.6 and python3.0
> at the *same* time. IMO, 2.6 should be compatible with 2.5 while 3.0
> is new style python. Currenly, most python projects works fine in 2.5.
> When 3.0 becomes final release, those projects will be gradually moved
> to 3.0. But even without the intermediate version 2.6, project
> transformation with be smooth enough, and then 2.5, 2.6 will be
> replaced by 3.0. I will not spend any time on studying 2.6. So why
> does python development team put many efforts on 2.6? What is the role
> of 2.6?
>
> Best regards,
>
> --
> ShenLei

2.6 is meant to be a continuation of the 2.x line of Python, to
support a gradual move of larger projects over to the Python 3.x
series. The idea is that as Python 3.x will cause some major and minor
changes to the basics of Python as we currently know it, trying to
move everyone straight away will be problematic.

Therefore the point is there will be a 2.7, 2.8 and so forth until
there is almost no difference between
the 2.x and 3.x at which time most users will have moved to the 3.x
series and the 2.x can be discontinued.

I will program larger projects in 2.5 for a while and then perhaps
look to move it to 2.6 and 2.7, I won't touch the 3.x series until it
is the common choice, much as a lot of people still program in 2.3/4.
--
http://mail.python.org/mailman/listinfo/python-list

Re: What is the role of python2.6 and C++?

2008-07-21 Thread Marc 'BlackJack' Rintsch
On Mon, 21 Jul 2008 16:17:00 +0800, 甜瓜 wrote:

> I'm confused about the motivation of releasing python2.6 and python3.0
> at the *same* time. IMO, 2.6 should be compatible with 2.5 while 3.0
> is new style python.

That's how it is.  2.6 is backwards compatible with 2.5.

> […] But even without the intermediate version 2.6, project transformation
> with be smooth enough, and then 2.5, 2.6 will be replaced by 3.0. I will
> not spend any time on studying 2.6. So why does python development team
> put many efforts on 2.6? What is the role of 2.6?

It's a version that makes the transition smoother.  You really should take
that "detour" via 2.6.  There should be some of the changes from 3.0 in 2.6
that don't mess with backwards compatibility, and a script that tries to
automate the conversion from 2.6 to 3.0.  This spares a lot of work when
porting to 3.0.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list

Odd math related issue.

2008-07-21 Thread Robert Rawlins
Guys,

 

I've got what seems to me to be a totally illogical math issue here which I
can't figure out. Take a look at the following code:

 

self.__logger.info("%i / %i" % (bytes_transferred,
self.__sessions[path].total_bytes))

percentage = bytes_transferred / self.__sessions[path].total_bytes *
100

self.__logger.info("%i" % percentage)

 

Seems fairly straight forward, you would think. It takes two values and
calculates the percentage of one from the other, however, percentage always
comes back as '0' for some reason, look at this log output.

 

2008-07-21 08:39:05,465 manager.py 78 INFO 290112 / 442435

2008-07-21 08:39:05,466 manager.py 80 INFO 0

 

Any suggestions as to why this might be the case? I'm sure it's something
dumb but I can't spot it.

 

Robert

--
http://mail.python.org/mailman/listinfo/python-list

Re: What is the role of python2.6 and C++?

2008-07-21 Thread 甜瓜
> I will program larger projects in 2.5 for a while and then perhaps
> look to move it to 2.6 and 2.7, I won't touch the 3.x series until it
> is the common choice, much as a lot of people still program in 2.3/4.

Oh, I see. It seems the gap between 2.5 and 3.0 is not so small.
Therefore, even if 3.0 is released, it may take many months for
porting old projects.
I agree with you to wait until python 3.0 becomes common choice. Hope
this day comes as soon as possible. :P

--
ShenLei
--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd math related issue.

2008-07-21 Thread Fredrik Lundh

Robert Rawlins wrote:

I’ve got what seems to me to be a totally illogical math issue here 
which I can’t figure out. Take a look at the following code:


/self/.__logger.info(/"%i / %i"/ % (bytes_transferred, 
/self/.__sessions[path].total_bytes))


percentage = bytes_transferred / 
/self/.__sessions[path].total_bytes * 100


/self/.__logger.info(/"%i"/ % percentage)

Seems fairly straight forward, you would think. It takes two values and 
calculates the percentage of one from the other, however, percentage 
always comes back as ‘0’ for some reason, look at this log output.


if you divide two integers, you'll get an integer back (in Python 2.X, 
at least).  quick fix:


 percentage = bytes_transferred * 100 / total_bytes



--
http://mail.python.org/mailman/listinfo/python-list


Re: checking if an object IS in a list

2008-07-21 Thread nicolas . pourcelot
On 20 juil, 07:17, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Sat, 19 Jul 2008 13:13:40 -0700, nicolas.pourcelot wrote:
> > On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> >> On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote:
> >> > So, I use something like this in 'sheet.objects.__setattr__(self,
> >> > name, value)':
> >> > if type(value) == Polygon:
> >> >     for edge in value.edges:
> >> >         if edge is_in sheet.objects.__dict__.itervalues():
> >> >             object.__setattr__(self, self.__new_name(), edge)
>
> >> > Ok, I suppose it's confused, but it's difficult to sum up. ;-)
>
> >> You are setting attributes with computed names?  How do you access them?
> >> Always with `gettattr()` or via the `__dict__`?  If the answer is yes, why
> >> don't you put the objects the into a dictionary instead of the extra
> >> redirection of an objects `__dict__`?
>
> > Yes, I may subclass dict, and change its __getitem__ and __setitem__
> > methods, instead of changing objets __setattr__ and __getattr__... But
> > I prefer
>  sheet.objects.A = Point(0, 0)
> > than
>  sheet.objects["A"] = Point(0, 0)
>
> But with computed names isn't the difference more like
>
> setattr(sheet.objects, name, Point(0, 0))
> vs.
> sheet.objects[name] = Point(0, 0)
>
> and
>
> getattr(sheet.objects, name)
> vs.
> sheet.objects[name]
>
> Or do you really have ``sheet.objects.A`` in your code, in the hope that
> an attribute named 'A' exists?
>
> >> Oh and the `type()` test smells like you are implementing polymorphism
> >> in a way that should be replaced by OOP techniques.
>
> > I wrote 'type' here by mistake, but I used 'isinstance' in my code. ;-)
>
> Doesn't change the "code smell".  OOP approach would be a method on the
> geometric objects that know what to do instead of a type test to decide
> what to do with each type of geometric object.
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Thank you for your advises, it's very interesting to have an external
point of view.

No, I have not anything like 'sheet.objects.A' in the library code,
but I use then the library in different programs where things like
sheet.objects.A sometimes occur.
However, since it is not so frequent, I may indeed subclass dict, and
change __getitem__, __setitem__ and __delitem__, and then redirect
__getattr__, __setattr__, __delattr__ to previous methods... This
would not break library external API, and it may speed-up a little
internal stuff.

I'm not very expert in OOP ; imho it's largely a mean and not a goal.
On one hand, 'a method on the geometric objects that know what to do'
would require them to contain some code concerning the object
manager... I don't like that very much. On the other hand, object
manager should not rely on object's implementation... I will think
about that.

Thank you all of you for your answers.
I'm sorry I may not have time to reply further, it was interesting :-)
(even if it's a bit difficult for me to write clearly in english ;-))
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the role of python2.6 and C++?

2008-07-21 Thread Fredrik Lundh

[EMAIL PROTECTED] wrote:


2.6 is meant to be a continuation of the 2.x line of Python, to
support a gradual move of larger projects over to the Python 3.x
series.


note that Python also has a tradition of releasing X.6 and (X+1).0 at 
the same time:


http://mail.python.org/pipermail/python-announce-list/2000-September/000513.html
http://mail.python.org/pipermail/python-list/2000-September/051263.html



--
http://mail.python.org/mailman/listinfo/python-list


RE: Odd math related issue.

2008-07-21 Thread Robert Rawlins
> if you divide two integers, you'll get an integer back (in Python 2.X, 
> at least).  quick fix:
>
>   percentage = bytes_transferred * 100 / total_bytes
>
> 

Hey 

That worked a charm mate, thanks for the info.



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Michiel
Overtoom wrote:

> Many major text/word processing programs (Emacs, vi, MS-Word) are also
> written in C. Does that mean you should do all your text processing in C?

How else would you implement a Boyer-Moore algorithm?
--
http://mail.python.org/mailman/listinfo/python-list


Re: atan2 weirdness

2008-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Carsten Haese wrote:

> Since pi is close to 3 ...

"Biblical pi" = 3.
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-21 Thread oj
On Jul 19, 3:04 am, Andrew Freeman <[EMAIL PROTECTED]> wrote:
> let me revise it please:
>
> To show if valid:
>
> if re.search(r'^[LRM]*$', 'LM'):
>     print 'Valid'

Fine, this works, although match instead of search blah blah blah as
has already been mentioned. I still think searching for one invalid
character is more elegant then trying to match the entire string, but
that's just personal preference, I guess.

>
> To show if invalid,
>
> if re.search(r'^[^LRM]*$', '0'):
>     print 'Inalid'

No. This is wrong. This only matches strings that consist entirely of
characters that are not L, R or M:

>>> import re
>>> if re.search(r'^[^LRM]*$', 'ZZZLZZZ'):
... print "Invalid"
...
>>>

This doesn't print "Invalid" because there is one non-invalid
character there, which is clearly not what the OP wanted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Iain King
On Jul 21, 6:58 am, "Krishnakant Mane" <[EMAIL PROTECTED]> wrote:

>
> First off all c# is absolute rubbish waist of time.  if I need to
> learn it then I better lern java or pythonfor that matter.  and by the
> way what is a "real programmer?"

The story of a Real Programmer:

http://www.pbm.com/~lindahl/mel.html

Iain
--
http://mail.python.org/mailman/listinfo/python-list


Re: db question

2008-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Dennis Lee
Bieber wrote:

> On Sun, 20 Jul 2008 18:43:03 -0700, "bruce" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>> 
>> mysql cmd - select * from foo where dog like "%small%";
>> 
>> sql ="""select * from foo where dog like "%%%s%%" """
>> c.execute(sql, (var,))
> 
> The execute statement is responsible quoting your literals, so the
> final statement you end up submitting looks like:
> 
> select * from foo where dog like ""%"xxx"%""
> 
> or some variant thereof.
> 
> Anything parameterized with %s must be a complete term!
> 
> Try:
> 
> sql = "select * from foo where dog like %s"
> c.execute(sql, ("%" + var + "%",) )
> 
> IOW: you need to massage the variable search term to include the
> wildcard % FIRST, then let MySQLdb substitute it (with surrounding
> quotes and escapes) into the SQL.

More general, less pitfall-prone solution:

select * from foo where dog like %s" %
SQLString("%" + EscapeSQLWild("small") + "%")

where SQLString and EscapeSQLWild are defined as in
.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Genetic programming: pygene, pygp, AST, or (gasp) Lisp?

2008-07-21 Thread david . leoni . dontemailthisaddress
John Ladasky said:
  Why not do genetic programming directly on Python code?

maybe Dione is what you are looking for - it seems to manipulate
Python asts directly

http://sourceforge.net/projects/dione/
--
http://mail.python.org/mailman/listinfo/python-list


calling source command within python

2008-07-21 Thread Jie
Hi all,

i'm having trouble executing os.system('source .bashrc') command
within python, it always says that source not found and stuff. Any
clue?

Thanks,
Jie
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-21 Thread Fredrik Lundh

oj wrote:


Fine, this works, although match instead of search blah blah blah as
has already been mentioned. I still think searching for one invalid
character is more elegant then trying to match the entire string, but
that's just personal preference, I guess.


The drawback is that it's a lot easier to mess up the edge cases if you 
do that (as this thread has shown).  The small speedup you get in 
typical cases is quickly offset by extra debugging/testing time (or, for 
that matter, arguing with c.l.py:ers over more or less contrived ways to 
interpret the original post).


Guess it's up to personal preferences for how to best help others. 
Unless the OP explicitly asks for something else, I prefer to use simple 
and straight-forward solutions with reasonable execution behaviour over 
clever tricks or odd-ball solutions; it's not a JAPH contest, after all.




--
http://mail.python.org/mailman/listinfo/python-list


Re: calling source command within python

2008-07-21 Thread Fredrik Lundh

Jie wrote:


i'm having trouble executing os.system('source .bashrc') command
within python, it always says that source not found and stuff. Any
clue?


like in

$ python
>>> import os
>>> os.system("source .bashrc")
sh: source not found and stuff
256

?  I get

$ python
>>> import os
>>> os.system("source .bashrc")
/... stuff printed by my .bashrc file .../
0

What happens if you do

>>> import os
>>> os.system("bash .bashrc")

instead?



--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-21 Thread oj
On Jul 21, 11:04 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> The drawback is that it's a lot easier to mess up the edge cases if you
> do that (as this thread has shown).  The small speedup you get in
> typical cases is quickly offset by extra debugging/testing time (or, for
> that matter, arguing with c.l.py:ers over more or less contrived ways to
> interpret the original post).

I disagree, from this thread, most of the erroneous solutions have
been attempts to match the entire string.

> Guess it's up to personal preferences for how to best help others.
> Unless the OP explicitly asks for something else, I prefer to use simple
> and straight-forward solutions with reasonable execution behaviour over
> clever tricks or odd-ball solutions; it's not a JAPH contest, after all.

[^LRM] *is* a simple and straight-forward regex - it isn't attempting
to do any clever tricks or anything odd-ball.

That said, I still think the sets solution is more elegant then the
regex solutions.
--
http://mail.python.org/mailman/listinfo/python-list


Parsing VHDL with python, where to start.

2008-07-21 Thread Svenn Are Bjerkem
Hi,
I am in the need to write an application for PyQt to visualise the
structure of a VHDL project I am working on. Looking for a sensible
way to parse VHDL files and putting them into a data structure that
PyQt can represent as a tree (or whatever the MVC is supporting)
through search engines does not give me many hints. From what I know,
VHDL is not a very easy language to parse. There seems to be a parser
for perl available, but I do not know if it is wise to use a perl
module as a template for writing something similar in python.

My initial idea is to start simple and extend features in my
application, but I fear that I may start off with wrong ideas how to
parse and then code myself into a dead-end requiring myself to rewrite
the whole application in order to get any further. I would start
finding definitions of entities and the instantiations of these and
build a tree from a set of external vhdl files stored in a file
hierarchy. If somebody have a starting point where to get going with a
task like this, I would be happy to know.

--
kind regards,
Svenn
--
http://mail.python.org/mailman/listinfo/python-list


Daemonize an application.

2008-07-21 Thread Robert Rawlins
Guys,

 

I've been looking to run one of my applications as a Deamon on a linux based
system. I've been looking at this recipe this morning and it all looks
relatively fine:

 

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731

 

I just noted that the recipe was written 5 years ago and thought I would see
if there have been any progressions in Python which allow a more native
approach to forking my application as a daemon?

 

I essentially want to add a command line parameter "--as-daemon" to my
application which would fork it as a daemon instead of running it as a
standard python script, I also want to ensure that stdin/out/err are all
configured in a way which means any exceptions thrown by the application or
data output to the command line, which I haven't foreseen will be stored in
a log file for review.

 

I'd really appreciate your advice and experience.

 

Cheers,

 

Robert

--
http://mail.python.org/mailman/listinfo/python-list

howto check is function capable of obtaining **kwargs?

2008-07-21 Thread dmitrey
hi all,
howto check is function capable of obtaining **kwargs?

i.e. I have some funcs like
def myfunc(a,b,c,...):...

some like
def myfunc(a,b,c,...,*args):...

some like
def myfunc(a,b,c,...,*args, **kwargs):...

some like
def myfunc(a,b,c,...,zz=zz0):...

So I need to know is the given function capable of handling zz
parameter, for example the call
myfunc(a,b,c,...,zz=4,...)

Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


Re: howto check is function capable of obtaining **kwargs?

2008-07-21 Thread Bruno Desthuilliers

dmitrey a écrit :

hi all,
howto check is function capable of obtaining **kwargs?

i.e. I have some funcs like
def myfunc(a,b,c,...):...

some like
def myfunc(a,b,c,...,*args):...

some like
def myfunc(a,b,c,...,*args, **kwargs):...

some like
def myfunc(a,b,c,...,zz=zz0):...

So I need to know is the given function capable of handling zz
parameter, for example the call
myfunc(a,b,c,...,zz=4,...)


inspect.getargspecs should give you the answer.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Genetic programming: pygene, pygp, AST, or (gasp) Lisp?

2008-07-21 Thread dmitrey
also, you could look at the simple openopt example provided by GA
"galileo" solver (connected to OO framework)
http://projects.scipy.org/scipy/scikits/browser/trunk/openopt/scikits/openopt/examples/glp_1.py
http://scipy.org/scipy/scikits/wiki/GLP
Regards, D
--
http://mail.python.org/mailman/listinfo/python-list


Re: Please recommend a RPC system working with twisted.

2008-07-21 Thread Diez B. Roggisch
一首诗 wrote:

> Hi all,
> 
> I'm looking for an RPC system working with twisted.
> 
> 1. Binary.  I want it run faster than any xml based RPC.
> 
> 2. Bidirectional.  Unlike  HTTP, on which the client has to poll the
> sever for events, the server should "call" the client's method to
> notify events.
> 
> 3. C/Python support.  Part of the system shall be written in C.

CORBA, especially the very good omniORB-implementation for Python.
 
> 4. Could easily integrated  with twisted.
> 
> Unfortunately, there seems no such resolution existed.  So maybe I
> have to give up some requirements.

The last one, yes. At least it should be possible to integrate using
threading though. And *maybe* you can even provide some event loop
integration as well - I think omniORB should be that flexible.

Diez
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python Written in C?

2008-07-21 Thread Bruno Desthuilliers

[EMAIL PROTECTED] a écrit :
(snip clueless nonsense)

Surely a troll... No one on earth can be *that* clueless.
--
http://mail.python.org/mailman/listinfo/python-list


How to install simplejson on WinXP

2008-07-21 Thread lookon
I am new to python and had difficulty in installing simplejson on
WinXP...Could anyone help me? Thanks
--
http://mail.python.org/mailman/listinfo/python-list


simple question about dictionaries

2008-07-21 Thread skazhy
hi, i am new to python, so i've a really simple question about
dictionaries.
if i have a dictionary and I make have an input after it (to input
numbers) can i get the key of value that was in input?

somehting like this:
dict = { "key1"=100,"key2"=200,"key3"=300}
a = input()
print 'the key of inputted value is', dict['a']

this syntax of course is wrong, but i hope you got the point..

thanks in advance!

--
http://mail.python.org/mailman/listinfo/python-list


Problem with Python Server Pages (PSP)

2008-07-21 Thread barun . saha04
Hi,

I am facing a very basic problem with PSP. I have installed mod_python
(in fedora Core 1), added the lines required for loading Python
modules and handling PSP pages. I have created a hello.psp page. But
when I try to view this hello.psp page, all Python code are getting
displayed.

The said page is stored at /var/www/html/psp/hello.psp. I guess this
is some configuration problem with Apache, but not able to figure out
the exact problem. I have tried putting those configuration lines for
psp in both httpd.conf and python.conf files. But still it is not
working.

The Python module (mod_python) is getting loaded. Because when I
telnet to my server, I can find that in the headers.

These are the versions of the softwares:
Apache: 2.0.47
Python: 2.2.3
mod_python: 3.0.3

Thnaks for all your suggestions.
--
http://mail.python.org/mailman/listinfo/python-list


Re: howto check is function capable of obtaining **kwargs?

2008-07-21 Thread Chris
On Jul 21, 1:20 pm, dmitrey <[EMAIL PROTECTED]> wrote:
> hi all,
> howto check is function capable of obtaining **kwargs?
>
> i.e. I have some funcs like
> def myfunc(a,b,c,...):...
>
> some like
> def myfunc(a,b,c,...,*args):...
>
> some like
> def myfunc(a,b,c,...,*args, **kwargs):...
>
> some like
> def myfunc(a,b,c,...,zz=zz0):...
>
> So I need to know is the given function capable of handling zz
> parameter, for example the call
> myfunc(a,b,c,...,zz=4,...)
>
> Thank you in advance, D.

>>> def f(a, b=1, c={}, *args, **kwargs):
pass

>>> inspect.getargspec(f)
(['a', 'b', 'c'], 'args', 'kwargs', (1, {}))

>>> print inspect.getargspec.__doc__
Get the names and default values of a function's arguments.

A tuple of four things is returned: (args, varargs, varkw,
defaults).
'args' is a list of the argument names (it may contain nested
lists).
'varargs' and 'varkw' are the names of the * and ** arguments or
None.
'defaults' is an n-tuple of the default values of the last n
arguments.

Hope that helps.
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about dictionaries

2008-07-21 Thread Berco Beute
Sounds like a school assignment. Find the answer yourself here:
http://diveintopython.org/toc/index.html

You'll learn a lot more in the process.

2B
--
http://mail.python.org/mailman/listinfo/python-list


Python Embedding Thread

2008-07-21 Thread otr2
Hi :)

I want to run Python in my app. That works still fine. But my app
supports now Threads and I would like to know what to do, that it runs
without problems.

PyGILState_Release and PyGILState_Ensure should solve the problem
right? Where do I have to put this two commands around? between each
Command that increase, decrease a reference?



Currently, this is a small code-snippet that represents the part of
the code-execution:






PyObject *f_globals=NULL, *f_locals=NULL, 
*mod=NULL, *rv=NULL;

mod = PyImport_ImportModule("__main__");
if (!mod)
return;

f_globals = PyModule_GetDict(mod);
f_locals = PyDict_New();
PyDict_Update(f_locals, f_globals);
if (!f_locals) {
Py_DECREF(mod);
PyErr_Print();
return;
}



rv = PyRun_String(  , 
Py_file_input, f_locals,
f_locals);
if (!rv)
PyErr_Print();


Py_XDECREF(rv);
Py_DECREF(mod);
Py_DECREF(f_locals);
Py_DECREF(f_locals);






Thanks a lot for your help :)


--
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about dictionaries

2008-07-21 Thread Fredrik Lundh

skazhy wrote:


hi, i am new to python, so i've a really simple question about
dictionaries.
if i have a dictionary and I make have an input after it (to input
numbers) can i get the key of value that was in input?


A dictionary contains (key, value) pairs, and is optimized for quickly 
finding the value in a pair, if given the key.



somehting like this:
dict = { "key1"=100,"key2"=200,"key3"=300}


dict() is a built-in function; you're free to reuse the names of such 
functions as variable names in Python, but if you do, you won't be able 
to use those functions in that part of your program.  And in this case, 
the dict() built-in might be useful (see below):



a = input()
print 'the key of inputted value is', dict['a']

this syntax of course is wrong, but i hope you got the point..


Assuming that you want the *key* in Python's sense, for a given value, 
you can either loop over the dictionary (called D below):


for k, v in D.items():
if v == a:
print 'the key of inputted value is', v
break
else:
print "not found"

or create an reverse mapping and use that (you only have to do this 
every time the dictionary changes, of course), e.g.


reverse_D = dict((D[k], k) for k in D)

a = input()
print "the key for value", a, "is", reverse_D[a]

(this doesn't work if you call your dictionary "dict", obviously.)



--
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about dictionaries

2008-07-21 Thread Jeff
On Jul 21, 7:35 am, skazhy <[EMAIL PROTECTED]> wrote:
> hi, i am new to python, so i've a really simple question about
> dictionaries.
> if i have a dictionary and I make have an input after it (to input
> numbers) can i get the key of value that was in input?
>
> somehting like this:
> dict = { "key1"=100,"key2"=200,"key3"=300}
> a = input()
> print 'the key of inputted value is', dict['a']
>
> this syntax of course is wrong, but i hope you got the point..
>
> thanks in advance!

I don't think there is a built-in that retrieves dict keys by value,
but if the dictionary were small enough, you could search the list of
key/value pairs returned by dict.items().  You can also iterate
through all pairs with dict.iteritems(), which returns an iterator.
Something like:

def key_by_value(dct, val):
  for k, v in dct.iteritems():
if v == val:
  return v
  throw KeyError('%s not found' % str(val))

--
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about dictionaries

2008-07-21 Thread Fredrik Lundh

Jeff wrote:


  throw KeyError('%s not found' % str(val))


"throw"?  and shouldn't that be a ValueError? ;-)



--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd math related issue.

2008-07-21 Thread Alexandru Palade

However, you should be carefully because using an %i modifier for a
what-should-be a float value truncates the value in a way you may not
expect.

What I mean is that if you have sent 2 out of 3 bytes, the math will be
200/3 which with the %i modifier will print 66, rather than 66.6 (or at
least 67 which is closer - have a look at the round() function).

Another thing, you could have just added a dot after the constant in
order to promote the expression to be evaluated as float. As in
   percentage = bytes_transferred / /self/.__sessions[path].total_bytes
* 100.
(notice the last dot)

Fredrik Lundh wrote:

Robert Rawlins wrote:

I’ve got what seems to me to be a totally illogical math issue here 
which I can’t figure out. Take a look at the following code:


/self/.__logger.info(/"%i / %i"/ % (bytes_transferred, 
/self/.__sessions[path].total_bytes))


percentage = bytes_transferred / 
/self/.__sessions[path].total_bytes * 100


/self/.__logger.info(/"%i"/ % percentage)

Seems fairly straight forward, you would think. It takes two values 
and calculates the percentage of one from the other, however, 
percentage always comes back as ‘0’ for some reason, look at this log 
output.


if you divide two integers, you'll get an integer back (in Python 2.X, 
at least).  quick fix:


 percentage = bytes_transferred * 100 / total_bytes



--
http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd math related issue.

2008-07-21 Thread Fredrik Lundh

Alexandru Palade wrote:


However, you should be carefully because using an %i modifier for a
what-should-be a float value truncates the value in a way you may not
expect.

What I mean is that if you have sent 2 out of 3 bytes, the math will be
200/3 which with the %i modifier will print 66, rather than 66.6 (or at
least 67 which is closer - have a look at the round() function).


My suggested workaround doesn't use floats.  As for rounding, that's 
more of a usability issue -- seeing the download process getting stuck 
at 100% can be rather frustrating for the poor user.  Better truncate 
towards zero.



Another thing, you could have just added a dot after the constant in
order to promote the expression to be evaluated as float. As in
   percentage = bytes_transferred / /self/.__sessions[path].total_bytes
* 100.
(notice the last dot)


Did you try that?

>>> 2 / 3 * 100.
0.0

You can fix this with parentheses, but I usually recommend an explicit 
"cast" instead, to make it obvious what you're doing:


result = float(a) / b



--
http://mail.python.org/mailman/listinfo/python-list


error

2008-07-21 Thread Anish Chapagain
from Tkinter import *
root=Tk()
f=Frame(root,height=200,width=200)
b=Button(f,text="quit",command=f.quit)
f.pack()
root.mainloop()

--
from Tkinter import *
import sys
root=Tk()
f=Frame(root,height=200,width=200)
b=Button(f,text="quit",command=sys.exit)
f.pack()
root.mainloop()

I am wondering that why the button after clikcing is not closing the
window..please any suggestion..
i tries command=f.quit, sys.quit also..
if there is something i'm missing please help
--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd math related issue.

2008-07-21 Thread John Machin
On Jul 21, 10:21 pm, Alexandru Palade
<[EMAIL PROTECTED]> wrote:
>
> Another thing, you could have just added a dot after the constant in
> order to promote the expression to be evaluated as float. As in
> percentage = bytes_transferred / /self/.__sessions[path].total_bytes
> * 100.
> (notice the last dot)
>

True, you get a float result, but not a very useful one:

>>> a = 2
>>> b = 11
>>> a / b * 100 # OP's problem
0
>>> a / b * 100. # Your suggestion; same as (a / b) *100.
0.0
>>> a * 100 / b # Fredrik's suggestion
18
>>> a * 100. / b # What you probably meant
18.181818181818183
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: error

2008-07-21 Thread Fredrik Lundh

Anish Chapagain wrote:


from Tkinter import *
root=Tk()
f=Frame(root,height=200,width=200)
b=Button(f,text="quit",command=f.quit)
f.pack()
root.mainloop()

--
from Tkinter import *
import sys
root=Tk()
f=Frame(root,height=200,width=200)
b=Button(f,text="quit",command=sys.exit)
f.pack()
root.mainloop()

I am wondering that why the button after clikcing is not closing the
window..please any suggestion..
i tries command=f.quit, sys.quit also..
if there is something i'm missing please help


Assuming you accidentally left out the line where you're displaying the 
button (e.g. "b.pack()"), both your samples work when running this from 
the command line.


Are you perhaps running this code from inside IDLE?  IDLE is itself 
written in Tkinter, and it doesn't always shut down the Tkinter 
subsystem properly.


... and I have to admit that I don't know what the currently recommended 
workaround is -- you'll find plenty of documentation on the net that 
just says "don't do that" (run Tkinter programs from within IDLE, that 
is), but surely someone should have fixed that issue by now?.




--
http://mail.python.org/mailman/listinfo/python-list


Re: How to install simplejson on WinXP

2008-07-21 Thread Fredrik Lundh

lookon wrote:


I am new to python and had difficulty in installing simplejson on
WinXP...Could anyone help me? Thanks


what did you try, and what happened when you tried that?



--
http://mail.python.org/mailman/listinfo/python-list


Re: error

2008-07-21 Thread Anish Chapagain
On Jul 21, 1:47 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Anish Chapagain wrote:
> > from Tkinter import *
> > root=Tk()
> > f=Frame(root,height=200,width=200)
> > b=Button(f,text="quit",command=f.quit)
> > f.pack()
> > root.mainloop()
>
> > --
> > from Tkinter import *
> > import sys
> > root=Tk()
> > f=Frame(root,height=200,width=200)
> > b=Button(f,text="quit",command=sys.exit)
> > f.pack()
> > root.mainloop()
>
> > I am wondering that why the button after clikcing is not closing the
> > window..please any suggestion..
> > i tries command=f.quit, sys.quit also..
> > if there is something i'm missing please help
>
> Assuming you accidentally left out the line where you're displaying the
> button (e.g. "b.pack()"), both your samples work when running this from
> the command line.
>
> Are you perhaps running this code from inside IDLE?  IDLE is itself
> written in Tkinter, and it doesn't always shut down the Tkinter
> subsystem properly.
>
> ... and I have to admit that I don't know what the currently recommended
> workaround is -- you'll find plenty of documentation on the net that
> just says "don't do that" (run Tkinter programs from within IDLE, that
> is), but surely someone should have fixed that issue by now?.
>
> - Hide quoted text -
>
> - Show quoted text -

hi thank's i probably missed the b.pack() but it's till the window is
not closed and error message of Windows Appear
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread ptn
On Jul 20, 5:50 pm, [EMAIL PROTECTED] wrote:
> I'm just learning about Python now and it sounds interesting. But I
> just read (on the Wiki page) that mainstream Python was written in C.
> That's what I was searching for: Python was written in what other
> language?
>
> See, my concern was something like: OK, if Python is so hot, then,
> hopefully someone is writing it in assembly language for each MPU chip
> out there. Otherwise, if, say, they've written it in C#, then it looks
> like the REAL, generally useful language to learn is C# and Python is
> akin to Visual Basic or something: a specialty languagewhereas
> REAL WORLD programmers who want to be generally useful go and learn
> C#.
>
> So I was suspecting the Python compiler or interpreter is written in a
> REAL language like C#. So, Wiki says it's written in C! It's almost as
> if it were an intentional trick...write your own, new language in an
> OLD, real world language that is passe. Compile it into executable
> modules of course, so it is a real, working compiler, alright. But the
> SOURCE is some old, high level language which no one wants to use
> anymore! So now you've got a hot new language package and no one can
> say "well, it is written in, the SOURCE code is written in, a REAL
> language." No, it's not! The source is some outdated language and
> compiler and no one is going to prefer learning THAT to learning your
> hot new language!
>
> I'm not dissing Python, here. Just noting that, if it is written in C,
> that throws a curve at me in trying to balance the value of learning
> Python vs. some other major language.


Sounds like you program only because someone's paying you. Any
programmer who says that C is outdated and not real *is* outdated and
not real.

Not used anymore? M I wonder, have you heard of something called
"Linux"? The open source Unix-like system? Or perhaps you are familiar
with "Apache"? Does "GNOME" ring any bells to you? "Vim"? "Git"? You
got some serious research to do, STFW.
--
http://mail.python.org/mailman/listinfo/python-list


ntlm authentication

2008-07-21 Thread Neuberger, Sheldon N.
Is there any way to make urllib2 handle NTLM authentication?

Sheldon Neuberger


--
http://mail.python.org/mailman/listinfo/python-list

how to create GUI dynamically

2008-07-21 Thread hitechpundir
Hi;

i m working on a project where i need  run time creation of GUI.

i have some no. of entities for which i want checkboxes in front of
them which can be checked/ unchecked by user.

But the problem is that the number and name of entities is not fixed
and it depends on the file which is used as input.

So is there any way to tackle this problem.

By the way ; i use Boa constructor (zope editor) for GUI now.

regards
pawan pundir
--
http://mail.python.org/mailman/listinfo/python-list


ANN: eGenix EuroPython 2008 Presentations & Videos

2008-07-21 Thread eGenix Team: M.-A. Lemburg




  eGenix EuroPython 2008 Presentations & Videos




We have uploaded our EuroPython 2008 presentations to our website.

Learn the concepts behind the Python DB-API and how to design
large-scale applications.

This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/EuroPython-2008-Presentations.html


INTRODUCTION

The EuroPython Conference is the one of the premier conferences for
Python & Zope users and developers. This year it was being held from
the 7th to 9th July in Vilnius, Lithuania.

eGenix was one of the founding members of the EuroPython conference
team and played a major role in organizing the first EuroPython
conference in the year 2002.

Since then we have attended every EuroPython conference to meet up
face-to-face with the people from the Python & Zope communities and
have given regular talks at these conferences.



TALKS AT EUROPYTHON 2008

We gave the following two talks at the conference. The presentations
are available for viewing and download from our Presentations and
Talks section:

http://www.egenix.com/library/presentations/

As special feature, we have added talk videos in addition to providing
the slide PDFs. You can view the talks online if you have the Adobe
Flash Player 8 or later installed.

* Using the Python Database API

The Python Database API (DB-API) is a specification of a module
interface that allows interfacing from Python to a relational database.

The talk gives a high-level introduction to the concepts used in the
Python DB-API and relational databases in general. Connection, cursors
and transactions are discussed, and their use in Python database
applications is explained.

* Designing Large-Scale Applications in Python

Python is widely and somewhat inaccurately referred to as a scripting
language. While Python is an ideal platform for small scripting tasks,
it does in fact cover all the concepts needed for large scale object
oriented application development. However, complex applications bring
different challenges.

This talk draws on eGenix' many years experience with large scale
application development using Python as central implementation language
and provides a cookbook approach to many of the the problems you face
when designing and organizing complex application frameworks.

Enjoy,
--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 21 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611

--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd math related issue.

2008-07-21 Thread sahasranaman
On Jul 21, 5:30 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Alexandru Palade wrote:
> > However, you should be carefully because using an %i modifier for a
> > what-should-be a float value truncates the value in a way you may not
> > expect.
>
> > What I mean is that if you have sent 2 out of 3 bytes, the math will be
> > 200/3 which with the %i modifier will print 66, rather than 66.6 (or at
> > least 67 which is closer - have a look at the round() function).
>
> My suggested workaround doesn't use floats.  As for rounding, that's
> more of a usability issue -- seeing the download process getting stuck
> at 100% can be rather frustrating for the poor user.  Better truncate
> towards zero.
>
> > Another thing, you could have just added a dot after the constant in
> > order to promote the expression to be evaluated as float. As in
> >    percentage = bytes_transferred / /self/.__sessions[path].total_bytes
> > * 100.
> > (notice the last dot)
>
> Did you try that?
>
>  >>> 2 / 3 * 100.
> 0.0
>
> You can fix this with parentheses, but I usually recommend an explicit
> "cast" instead, to make it obvious what you're doing:
>
>      result = float(a) / b
>
> 

Use 2.0 / 3 * 100 to solve this. Why make things look bigger?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Odd math related issue.

2008-07-21 Thread sahasranaman
On Jul 21, 5:30 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Alexandru Palade wrote:
> > However, you should be carefully because using an %i modifier for a
> > what-should-be a float value truncates the value in a way you may not
> > expect.
>
> > What I mean is that if you have sent 2 out of 3 bytes, the math will be
> > 200/3 which with the %i modifier will print 66, rather than 66.6 (or at
> > least 67 which is closer - have a look at the round() function).
>
> My suggested workaround doesn't use floats.  As for rounding, that's
> more of a usability issue -- seeing the download process getting stuck
> at 100% can be rather frustrating for the poor user.  Better truncate
> towards zero.
>
> > Another thing, you could have just added a dot after the constant in
> > order to promote the expression to be evaluated as float. As in
> >    percentage = bytes_transferred / /self/.__sessions[path].total_bytes
> > * 100.
> > (notice the last dot)
>
> Did you try that?
>
>  >>> 2 / 3 * 100.
> 0.0
>
> You can fix this with parentheses, but I usually recommend an explicit
> "cast" instead, to make it obvious what you're doing:
>
>      result = float(a) / b
>
> 

try 2.0 / 3 * 100
that would solve all trouble
--
http://mail.python.org/mailman/listinfo/python-list


imported module no longer available

2008-07-21 Thread Jeff Dyke
I've come across an error that i'm not yet able to create a test case
for but wanted to get see if someone could shed light on this.

I have imported a module at the top of my file with
import mymodulename

this module is used many times in the current file successfully, but
then I attempt to use it one more time and get: UnboundLocalError:
local variable 'mymodulename' referenced before assignment

if i add `print globals().keys()` right before the line where the
error occurs l see the module in the list (actual output, names
changed to protect the innocent)
['HPADao', 'RDao', 'DriverBase', 'FKSUtility', 'PMDao',
'mymodulename', 'IDriver', 'DriverTrack', 'HPPDao', 'setLogName',
'HPDao', 'iparser', '__builtins__', '__file__', 'driver', '_LOGNAME',
'sys', 'IClient', '__name__', 'copy', 'types', 'logging', 'iloader',
'HPADao', '__doc__', 'PMDao', 'time', 'FormatLoad']
Traceback (most recent call last):
  File "testunbound.py", line 475, in 
driver.getRData('0605', 22528)
  File "testunbound.py", line 256, in getRData
print mymodulename

the code that generates these two lines is:
print globals().keys()
print mymodulename

I can solve this by placing
import mymodulename again in this method, but can't have that everywhere.

I will try to come up with a generic reproduction of this issue, but
that might take some time.  I've also seen this in the past with the
python builtin 'sys'
I did see a bug http://bugs.python.org/issue2378, which has very
similar behaviour, but is different.

Python 2.5, ubuntu hardy

Thanks for any insight,
Jeff
--
http://mail.python.org/mailman/listinfo/python-list


Almost keywords

2008-07-21 Thread bearophileHUGS
Once in a while I feel free to write about less defined things, saying
mostly wrong things. This post is mostly chat, if you aren't
interested please ignore it.

Python is fit enough for newbie programmers, but some of its
characteristics can confuse them still, like the variables referenced
by name (that can be solved with a language that gives the illusion of
always manging values), the finite nature of floating point numbers
(that may be partially solved with interval arithmetic used in a smart
way, even if it may end being quite slower than Python floats), the
case sensitivity of all the language (in natural languages the case is
often irrelevant), the absence of rational numbers from integer
divisions, the code formatting precision required by significant
indentations, the "artificial" difference between lazy and eager
things, the silly syntax of tuples, some problems with closures that
partially come from automatic creation of variable names, many
inconsistencies present in the standard library, etc. Python 3.0
solved some of those problems, especially the smaller ones (for
example the "nonlocal" keyword workaround, etc).

If you take a look at the Python newsgroup, you can see that newbies
there do many similar mistakes all the time. A language fit for
newbies can adapt itself to avoiding those most common mistakes (but
today Python is becoming larger and more complex, more fit for real
programmers and less for programming newbies. This may be inevitable
in the evolution of a a language with commercial success). One of the
mistakes you see often is the rebinding of built-in things, like map,
list, etc. (Python 3.0 again turns some of those names into keywords,
avoiding part of those problems).

So you can see code like this that may lead to bugs in programs
written by newbies:
list = [x*x for x in range(100)

A possible way to avoid such bugs is to turn all those names like
"list", "map", "filter", "self", etc into keywords. But this may have
some disadvantages (well, I think I'd like to have "self" as keyword,
seen how all Python books strong suggest to not use a name different
from "self"). An intermediate solution is to change Python so that it
allows you to rebind those half-keywords only of you want it and you
know what you are doing, with a kind of comment at the top of the
module:

# rebinding = True
This allows you to do:
list = [x*x for x in range(100)]

By default rebinding is False, so this produces a SyntaxError:
list = [x*x for x in range(100)]

This may be a silly idea. Designing a good syntax for a language isn't
easy at all.

Note that a widely used Scheme implementation, DrScheme, implements
various sub-languages fit for newbies or almost-newbies or low-
experienced programmers. What is possible for experts can be a syntax
error for newbies. I don't like this feature much, I like more
freedom, but for purely learning purposes it may have its place. So
what I have said regarding the "almost keywords" isn't a totally new
idea :-)

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: error

2008-07-21 Thread Fredrik Lundh

Anish Chapagain wrote:


hi thank's i probably missed the b.pack() but it's till the window is
not closed and error message of Windows Appear


what does that error message say?



--
http://mail.python.org/mailman/listinfo/python-list


Re: imported module no longer available

2008-07-21 Thread Mark Tolonen


"Jeff Dyke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

I've come across an error that i'm not yet able to create a test case
for but wanted to get see if someone could shed light on this.

I have imported a module at the top of my file with
import mymodulename

this module is used many times in the current file successfully, but
then I attempt to use it one more time and get: UnboundLocalError:
local variable 'mymodulename' referenced before assignment

if i add `print globals().keys()` right before the line where the
error occurs l see the module in the list (actual output, names
changed to protect the innocent)
['HPADao', 'RDao', 'DriverBase', 'FKSUtility', 'PMDao',
'mymodulename', 'IDriver', 'DriverTrack', 'HPPDao', 'setLogName',
'HPDao', 'iparser', '__builtins__', '__file__', 'driver', '_LOGNAME',
'sys', 'IClient', '__name__', 'copy', 'types', 'logging', 'iloader',
'HPADao', '__doc__', 'PMDao', 'time', 'FormatLoad']
Traceback (most recent call last):
 File "testunbound.py", line 475, in 
   driver.getRData('0605', 22528)
 File "testunbound.py", line 256, in getRData
   print mymodulename

the code that generates these two lines is:
print globals().keys()
print mymodulename

I can solve this by placing
import mymodulename again in this method, but can't have that everywhere.

I will try to come up with a generic reproduction of this issue, but
that might take some time.  I've also seen this in the past with the
python builtin 'sys'
I did see a bug http://bugs.python.org/issue2378, which has very
similar behaviour, but is different.

Python 2.5, ubuntu hardy

Thanks for any insight,
Jeff


That error will occur if somewhere in a function or method you accidently 
assign another value to a global variable, without declaring it with the 
global keyword first, even if it occurs later in the function.  Example:


   import os
   print os.getcwd()
   def func():
   print globals().keys()
   print os
   os=1
   func()

OUTPUT:

   c:\
   ['__builtins__', '__file__', 'func', '__name__', 'os', '__doc__']
   Traceback (most recent call last):
 File 
"C:\dev\python\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", 
line 414, in ImportFile

   exec codeObj in __main__.__dict__
 File "", line 1, in 
 File "test.py", line 10, in 
   func()
 File "test.py", line 7, in func
   print os
   UnboundLocalError: local variable 'os' referenced before assignment

Check in the function that caused the error to see if later in the code the 
module name is being used as a local variable.


--Mark 


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Martin P. Hellwig

Bruno Desthuilliers wrote:

[EMAIL PROTECTED] a écrit :
(snip clueless nonsense)

Surely a troll... No one on earth can be *that* clueless.

I disagree he has upper management written all over him.

--
mph
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the role of python2.6 and C++?

2008-07-21 Thread Ulrich Eckhardt
甜瓜 wrote:
> Another question is about the future of C++. I am a C++ programmer.
> Since I studied python, most of my projects becomes written in python
> because of the better and simpler OOP representation. As a supplement,
> I use python C extension for computational extensive jobs. Therefore,
> for a relatively long time, I do not use C++ any more... Anyone is
> same to me? What is your attitude to the role of C++ in the age of
> python?

I guess the key here is "agile programming". Python allows you to quickly
change things, sometimes even on the fly and test them using the
interpreter. C++ offers high performance while still providing a high-level
interface. In fact using Boost.Python, it is even a piece of cake to
integrate C++ code into Python, including automatic conversion of things
like std::string or exceptions.

My personal feeling is that neither of the two is going away, last but not
least because of the large amounts of existing C and C++ code.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

--
http://mail.python.org/mailman/listinfo/python-list

Re: Odd math related issue.

2008-07-21 Thread Fredrik Lundh

sahasranaman wrote:


Use 2.0 / 3 * 100 to solve this. Why make things look bigger?


you mean that

a.0 / 3 * 100

works in your Python version?  that's interesting.

(maybe you should at least skim the the thread before you jump in?)



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread rynt
On Jul 20, 3:50 pm, [EMAIL PROTECTED] wrote:
> I'm just learning about Python now and it sounds interesting. But I
> just read (on the Wiki page) that mainstream Python was written in C.
> That's what I was searching for: Python was written in what other
> language?
>
> See, my concern was something like: OK, if Python is so hot, then,
> hopefully someone is writing it in assembly language for each MPU chip
> out there. Otherwise, if, say, they've written it in C#, then it looks
> like the REAL, generally useful language to learn is C# and Python is
> akin to Visual Basic or something: a specialty languagewhereas
> REAL WORLD programmers who want to be generally useful go and learn
> C#.
>
> So I was suspecting the Python compiler or interpreter is written in a
> REAL language like C#. So, Wiki says it's written in C! It's almost as
> if it were an intentional trick...write your own, new language in an
> OLD, real world language that is passe. Compile it into executable
> modules of course, so it is a real, working compiler, alright. But the
> SOURCE is some old, high level language which no one wants to use
> anymore! So now you've got a hot new language package and no one can
> say "well, it is written in, the SOURCE code is written in, a REAL
> language." No, it's not! The source is some outdated language and
> compiler and no one is going to prefer learning THAT to learning your
> hot new language!
>
> I'm not dissing Python, here. Just noting that, if it is written in C,
> that throws a curve at me in trying to balance the value of learning
> Python vs. some other major language.

You're either ---
A.  A Troll
B.  A young, immature programmer trying to show off
or
C.  A total idiot.

Who cares what language a language is written in as long as you can be
productive - which you certainly can be in Python.

RCB
--
http://mail.python.org/mailman/listinfo/python-list


Re: imported module no longer available

2008-07-21 Thread Fredrik Lundh

Jeff Dyke wrote:


I've come across an error that i'm not yet able to create a test case
for but wanted to get see if someone could shed light on this.

I have imported a module at the top of my file with
import mymodulename

this module is used many times in the current file successfully, but
then I attempt to use it one more time and get: UnboundLocalError:
local variable 'mymodulename' referenced before assignment


Let me guess: you've done

def myfunc():
print mymodulename
import mymodulename

or something similar?  Getting an exception in this case is the excepted 
behaviour; the reason being that a variable in a block only belongs to a 
single scope. for the entire block.  For details, see:


http://docs.python.org/ref/naming.html

Especially this section:

"If a name binding operation occurs anywhere within a code block, all 
uses of the name within the block are treated as references to the 
current block. This can lead to errors when a name is used within a 
block before it is bound. This rule is subtle. Python lacks declarations 
and allows name binding operations to occur anywhere within a code 
block. The local variables of a code block can be determined by scanning 
the entire text of the block for name binding operations."


To fix this, mark the name as global:

def myfunc():
global mymodulename # I mean the global name!
print mymodulename
import mymodulename



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Fredrik Lundh

rynt wrote:


You're either ---
A.  A Troll
B.  A young, immature programmer trying to show off
or
C.  A total idiot.


you forgot the "All of the above" choice.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Matthew Fitzgibbons

Martin P. Hellwig wrote:

I disagree he has upper management written all over him.



In any case, the OP should remember that programming languages are all 
theoretically the same: if you can do it in one language, then you can 
theoretically do it any other. When choosing a language, you just need 
to find one that (a) has the right tools to do the job (libraries, 
methods of deployment, supported platforms, etc.) and (b) that you and 
your team are comfortable using. Python has the tools to tackle a huge 
range of problems (you can often use the standard library when you would 
have to write C code from scratch), and many find it, dare I say, fun to 
use (whereas I find C# roughly equivalent to being shot). Whether you 
should use it depends on your domain and your team's preference.


-Matt
--
http://mail.python.org/mailman/listinfo/python-list


Website Creation using Python

2008-07-21 Thread Amie
Afternoon,

I would like some help on how to create a website using the python
programming language.
I've tried using enamel, but had some problems because I could not
create html tables and intergrating it with python, like you use it
when coding in php.

Any help would be appreciated.

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: ntlm authentication

2008-07-21 Thread Tim Golden

Neuberger, Sheldon N. wrote:

Is there any way to make urllib2 handle NTLM authentication?


Frankly, I'd hate to try. Have a look at this:

http://sourceforge.net/projects/ntlmaps/

in case it helps, either by providing a solution or
at least by illustrating some code.

In addition, look at the sspi package in the latest
pywin32 releases. There some sample code in
the demos area there, too. Haven't used it myself
(and I know it's messy) but I'm sure someone must
have.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Safe guard .pyc files

2008-07-21 Thread King
After google a lot I didn't find any way to safe guard .pyc files from
decompilation. One way I can think of is to
wrap important functions/classes as a libraby using SWIG/PyRex, but
again is going to be a lot more of work
and doesn't sound good.

any body out there has done something for this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Safe guard .pyc files

2008-07-21 Thread Fredrik Lundh

King wrote:


After google a lot I didn't find any way to safe guard .pyc files from
decompilation.


There's no bullet-proof way to do that (the interpreter needs the 
bytecodes to be able to run your program, so unless you create your own 
Python runtime, someone could always run your program with an 
instrumented stock interpreter, and get the code from there.  If you 
build your own runtime, they'll just instrument your runtime instead, 
which might be a little more work, but not much for someone who knows 
how to do such things.)


Possible solutions:

- implement portions of your application as a web service

- hardware dongles (hackers can usually get around them without too much 
work, but they work pretty well for some applications / markets.)


- use an obfuscator, e.g.

  http://bitboost.com/#other or
  http://www.lysator.liu.se/~astrand/projects/pyobfuscate/



--
http://mail.python.org/mailman/listinfo/python-list


Re: ntlm authentication

2008-07-21 Thread Grant Edwards
On 2008-07-21, Tim Golden <[EMAIL PROTECTED]> wrote:
> Neuberger, Sheldon N. wrote:
>> Is there any way to make urllib2 handle NTLM authentication?
>
> Frankly, I'd hate to try. Have a look at this:
>
> http://sourceforge.net/projects/ntlmaps/

Here's a library that can be used to handle the NTLM
authentication stuff:

  http://josefsson.org/libntlm/

There's no reason you couldn't translate it into Python (or
just call it).

-- 
Grant Edwards   grante Yow! I wonder if I could
  at   ever get started in the
   visi.comcredit world?
--
http://mail.python.org/mailman/listinfo/python-list


Re: sending input to an embedded application

2008-07-21 Thread Matthew Fitzgibbons

mefyl wrote:

Uwe Schmitt wrote:

On 12 Jul., 09:08, George Oliver <[EMAIL PROTECTED]> wrote:

What I would like to do is take a program and embed it or put it
within a Python-run GUI, using the GUI just to capture and send input
to the application, and display the ouput.

Which interface does your interpreter provide ? Just commandline or
can you access by other methods ?

http://sourceforge.net/projects/pexpect/ might help you



Although Pexpect looks more advanced and complete, you might want to take a
look at popen* modules. It enables you to easily run a subprocess, feed him
data on stdin, retrieve output from stdout/stderr, and wait for its
completion.

http://docs.python.org/lib/module-popen2.html



I believe the subprocess module is the recommended module to use now.

-Matt
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to create GUI dynamically

2008-07-21 Thread TheSeeker
On Jul 21, 8:19 am, [EMAIL PROTECTED] wrote:
> Hi;
>
> i m working on a project where i need  run time creation of GUI.
>
> i have some no. of entities for which i want checkboxes in front of
> them which can be checked/ unchecked by user.
>
> But the problem is that the number and name of entities is not fixed
> and it depends on the file which is used as input.
>
> So is there any way to tackle this problem.
>
> By the way ; i use Boa constructor (zope editor) for GUI now.
>
> regards
> pawan pundir

Hi,

Boa constructor can be used for the main part of the application, but
you'll probably need to 'roll your own' builder of the dynamic portion
(which isn't very hard).

A wonderful list for these kinds of questions is:
https://lists.sourceforge.net/lists/listinfo/boa-constructor-users

Duane
--
http://mail.python.org/mailman/listinfo/python-list


Re: Weird Python startup behavior between different drives on PowerPC platform

2008-07-21 Thread jwahlmann
Bump.  Anyone have any ideas on this?  My next step is to either link
together a static version of the compiler or create a debug version.

Thanks,
Jon

On Jul 18, 11:43 am, [EMAIL PROTECTED] wrote:
> I'm experiencing some strange behavior when starting up python on a
> Debian-based PowerPC platform.  Normally, I operate from this platform
> with a root file system on an IDE flash drive (/dev/hda1).  However,
> I'm trying to get my system to run with root on a mechanical SATA
> drive (/dev/sda1).  Both are installed on a PowerPC board via a PMC
> daughter board.
>
> When running off the flash drive, the Python interpreter loads and
> runs just fine.  However, when running from SATA, the interpreter
> seems to have problems with importing things like site, os, etc.  I've
> played around with PYTHONHOME to no effect.  I even went as far as
> setting PYTHONHOME to some off the wall location (so no stdlibs will
> load) and invoking Python as:
>
> host$ PYTHONHOME=/tmp python -d -v -S
> # installing zipimport hook
> import zipimport # builtin
> # installed zipimport hook
> Python 2.4.4 (#2, Apr  5 2007, 19:01:44)
> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2>>> i=0
>
>   File "", line 1
> i=0
>  ^
> SyntaxError: invalid syntax
>
>
>
> You'll note that doing something as simple as setting "i=0" results in
> a syntax error.  If I run the same thing on the IDE flash drive, it
> works:
>
> host$ PYTHONHOME=/tmp python -d -v -S
> # installing zipimport hook
> import zipimport # builtin
> # installed zipimport hook
> Python 2.4.4 (#2, Apr  5 2007, 19:01:44)
> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
>
> >>> i=0
>
> Any ideas?!  What could possibly cause a difference of operation
> between running from a IDE flash drive (/dev/hda1) vs. SATA (/dev/
> sda1)?  Other than toggling hda1 vs. sda1 in /etc/fstab, the
> filesystems are being built identically.  Could it be that shared
> libraries aren't being loaded correctly or fast enough off the SATA
> drive vs. flash?  Shooting in the dark here...
>
> Thanks,
> Jon Wahlmann

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread mk

Grant Edwards wrote:


Using punch-cards and paper-tape.  Real programmers can edit
their programs with a pointy stick and some home-made
sticky-tape.


Wrong! Real programmers can program using only Touring machine (and 
something having to do with post for some reason). I'm sure our 
brilliant OP[1] could program in both.


[1] Troll, really. Don't feed the troll. I wouldn't have posted about 
him because that only adds to the noise. oops.








--
http://mail.python.org/mailman/listinfo/python-list


Getting the name of a variable which was used as a function parameter.

2008-07-21 Thread Ravi Kotecha
Hi guys,

I thought this was pretty cool and since I spent 30 mins or so
goggling before giving up and figuring out myself I thought I'd share
it with you.

>>> def a(a):
... for k,v in sys._getframe(1).f_locals.items():
... if id(v) == id(a):
... print k
...

>>> hello = 123

>>> a(hello)
hello

## pretty cool.


It's totally useless but I wanted to do it for logging purposes.  It
will still return weird results if you have two labels pointing to the
same object but I'm not sure how to get around that, any ideas?

Regards,
Ravi Kotecha
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Tim Golden

mk wrote:

Grant Edwards wrote:


Using punch-cards and paper-tape.  Real programmers can edit
their programs with a pointy stick and some home-made
sticky-tape.


Wrong! Real programmers can program using only Touring machine


Is that some kind of bicycle?

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Seriously, though, about LLVM

2008-07-21 Thread mk


http://llvm.org/

This project has gained some publicity. There's IronPython, right, so 
has anybody thought about implementing Python using LLVM as backend, as 
it seems not out of question at all?



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Fredrik Lundh

Tim Golden wrote:


Wrong! Real programmers can program using only Touring machine


Is that some kind of bicycle?


there's a nearly infinite number of software projects with that name, 
but the Ultimate Touring Machine could be found in sydney not long ago:


http://tinyurl.com/5t2dl4



--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-21 Thread Derek Martin
On Fri, Jul 18, 2008 at 10:34:41PM -0700, Dennis Lee Bieber wrote:
> On Fri, 18 Jul 2008 19:14:43 -0400, Derek Martin <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
> > On Fri, Jul 18, 2008 at 03:46:13PM -0700, Joel Teichroeb wrote:
> > > Calling Windows PC seems to be something that Apple did so they would 
> > > not have to directly mention Windows. 
> > 
> > Actually it's something IBM did when they created the IBM PC.  Of
> 
> Bah... PC was short for Personal Computer... 

I'm well aware... congratulations on completely missing the point.  I
was describing how the term PC has become synonimous with Windows
machines.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpbl4K02hAFc.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python Written in C?

2008-07-21 Thread Marcus.CM

Hi everyone,

Yes, python is written in C. Maybe the original poster is looking for 
"ultimate" language and thus finds it uncomfortable that python should 
be written in C and not python itself.
Actually it doesnt matter if IronPython is written in C# and Python in 
C. Each programming language is like a tool to the programmer and no, C 
is not outdate, its just a language with a much higher learning curve
and its best left to do stuffs requiring drivers or optimized algorithms 
and other embedded stuffs that is usable by other languages. What do you 
think C# is written in? C# ?

You see how flawed this logic is.
Anyway, good luck on your search. But why look for "ultimate" language, 
when the core difference is the "programmmer" him/herself. In the hands 
of an skilled programmer, any language could accomplish much and then 
there is an issue with "time". I would cringe to do in C what i do in 
python nowadays, and i have like 14 years of C/C++ programming 
background. Someone wrote bittorrent in python and today its Utorrent 
written in C/C++ that is "cool", you see that doesnt mean that the next 
guy wrote write it in python would not beat the cool factor, its a 
matter of design, look, feel and its all about the programmer.


Like they say in racing, its the driver not the car.





--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread mk



Who cares what language a language is written in as long as you can be
productive - which you certainly can be in Python.


Seriously, though, would there be any advantage in re-implementing 
Python in e.g. C++?


Not that current implementation is bad, anything but, but if you're not 
careful, the fact that lists are implemented as C arrays can bite your 
rear from time to time (it recently bit mine while using lxml). Suppose 
C++ re-implementation used some other data structure (like linked list, 
possibly with twists like having an array containing pointers to 1st 
linked list elements to speed lookups up), which would be a bit slower 
on average perhaps, but it would behave better re deletion?



--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Marcus.CM

Its called a BMW today.


Fredrik Lundh wrote:

Tim Golden wrote:


Wrong! Real programmers can program using only Touring machine


Is that some kind of bicycle?


there's a nearly infinite number of software projects with that name, 
but the Ultimate Touring Machine could be found in sydney not long ago:


http://tinyurl.com/5t2dl4



--
http://mail.python.org/mailman/listinfo/python-list




--
http://mail.python.org/mailman/listinfo/python-list


Re: Seriously, though, about LLVM

2008-07-21 Thread Fredrik Lundh

mk wrote:

This project has gained some publicity. There's IronPython, right, so 
has anybody thought about implementing Python using LLVM as backend, as 
it seems not out of question at all?


you mean like:

http://llvm.org/ProjectsWithLLVM/#pypy

?



--
http://mail.python.org/mailman/listinfo/python-list


RE: Python Written in C?

2008-07-21 Thread Michael . Coll-Barth
 

> 
> From: mk

> Wrong! Real programmers can program using only Touring machine (and 
> something having to do with post for some reason). I'm sure our 
> brilliant OP[1] could program in both.

Ah, now we can really got OT.  My favorite Touring machine is a Jaguar (
with the pronounced 'U' in there ).  Oh, you meant "Turing";
.  

Sorry, I just couldn't resist after the tortured route this thread has
taken.


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Please recommend a RPC system working with twisted.

2008-07-21 Thread mk



Unfortunately, there seems no such resolution existed.  So maybe I
have to give up some requirements.


Why not PYRO? Note: I haven't used it.


--
http://mail.python.org/mailman/listinfo/python-list


Re: win32api not found?

2008-07-21 Thread norseman


Lamonte Harris wrote:

Where can I get the win32api module? I been searching all day on google and
nothing, i installed
https://sourceforge.net/project/showfiles.php?group_id=78018 which requires
win32api and its not found...





--
http://mail.python.org/mailman/listinfo/python-list


I followed the links from python.org to Mark Harmond's win32 package.
It loads into (in my case) c:\\Python25\\Lib\\site-packages\\win32 as 
win32api.pyd


Also: try the  import win32api  command another has suggested before 
searching all over.


HTH
Steve
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: imported module no longer available

2008-07-21 Thread Jeff Dyke
my apologies, to Fredrick, my response when solely to him.  reply
below, hopefully keeping thread intact.

On Mon, Jul 21, 2008 at 12:28 PM, Jeff Dyke <[EMAIL PROTECTED]> wrote:
> On Mon, Jul 21, 2008 at 10:19 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>> Jeff Dyke wrote:
>>
>>> I've come across an error that i'm not yet able to create a test case
>>> for but wanted to get see if someone could shed light on this.
>>>
>>> I have imported a module at the top of my file with
>>> import mymodulename
>>>
>>> this module is used many times in the current file successfully, but
>>> then I attempt to use it one more time and get: UnboundLocalError:
>>> local variable 'mymodulename' referenced before assignment
>>
>> Let me guess: you've done
>>
>>def myfunc():
>>print mymodulename
>>import mymodulename
>
> actually no, the only things in that fucntion were.
>print globals().keys() - i see it here
>print mymodulename - it fails here.
>
> the `import mymodulename` statement is at the very top of the file.
>
> plus the processing that was attempted after.  in fact in the calling
> method i was able to execute print mymodulename and it printed the
> expected python output.
>
>>
>> or something similar?  Getting an exception in this case is the excepted
>> behaviour; the reason being that a variable in a block only belongs to a
>> single scope. for the entire block.  For details, see:
>>
>>http://docs.python.org/ref/naming.html
>>
>> Especially this section:
>>
>> "If a name binding operation occurs anywhere within a code block, all uses
>> of the name within the block are treated as references to the current block.
>> This can lead to errors when a name is used within a block before it is
>> bound. This rule is subtle. Python lacks declarations and allows name
>> binding operations to occur anywhere within a code block. The local
>> variables of a code block can be determined by scanning the entire text of
>> the block for name binding operations."
>>
>> To fix this, mark the name as global:
>>
>>def myfunc():
>>global mymodulename # I mean the global name!
>>print mymodulename
>>import mymodulename
>
>
> So i went back to check that the name 'mymodulename' was not getting
> overwritten by something else and the error went away.  I've been
> working on something else entirely for the past few hours and have
> changed none of the code...and now it works.  which is even more
> troublesome then the error itself.
>
> Follow on question.  If this name, mymodulename, was imported in some
> other module.fucntion local to a function like
> def anotherfunc():
>import mymodulename
>
> would that remove it from the globals() and save it to a locals() ?  I
> would assume the answer to be no.
>
> Thanks for you response.
> Jeff
>
>
>>
>> 
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-21 Thread Derek Martin
On Sat, Jul 19, 2008 at 02:56:07AM -0700, Lie wrote:
> On Jul 19, 6:14 am, Derek Martin <[EMAIL PROTECTED]> wrote:
> > On Fri, Jul 18, 2008 at 03:46:13PM -0700, Joel Teichroeb wrote:
> > Much like the English word "bank" (and numerous others), the term "PC"
> > has come to have several meanings, one of which is the above.  You may
> > not like it, but we're pretty much stuck with the term, so you may as
> > well get used to it.
>
> That's not the point, 

It very much IS the point.  Language evolves based on common usage
patterns of the people who use it.  The term "PC" is commonly used in
English, in the United States and other English speaking countries, to
mean a computer running Microsoft Windows.  That's a simple fact that
you can not escape, no matter how much you may not like it (it just so
happens that I also don't like it, but I realized long ago the
futility of arguing against its usage).  It's still a fact, and I
described roughly how that fact came to be.  It wasn't something that
Apple started; it's been used this way in increasingly common usage
for at least 20 years, although exactly what combination of hardware
and software was being refered to as a "PC" has evolved over that
timeframe.

PC was a short form of "personal computer", which is how IBM came up
with the name.  Nevertheless, with the ubiquity of IBM hardware, and
subsequent popularity of clones running Microsoft operating systems,
the term "PC" has, in the present day, come to mean "a personal
computer based on Intel-compatible hardware running a flavor of
Microsoft Windows."  It is used this way by the consumer computer
industry, and it is used this way by the common population.  Ipso
facto "PC" means a windows box, in common English usage today.

You don't have to like it, and you don't even have to acknowledge it.
But if you choose not to, or argue against using it that way, you're
in denial, plain and simple.  

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpLN8hSeYEOH.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python Embedding Thread

2008-07-21 Thread googler . 1 . webmaster
Does anyone has a tip?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Matthew Woodcraft
Roy Smith  <[EMAIL PROTECTED]> wrote:
> C is the highest level assembler language I've ever used.  And I've used a 
> few.  It really is cool that you can add two 32-bit integers and not have 
> to worry about all those carry bits.

I was ever so pleased when I found out that the LLVM people have
learned this lesson from C.

I look forward to the day when we can have similar treatment for all
forms of error checking. Programming will be so much easier.

-M-

--
http://mail.python.org/mailman/listinfo/python-list


Re: Run as Service

2008-07-21 Thread Larry Bates

[EMAIL PROTECTED] wrote:

I have, in the past, used SRVANY to run a Python app as a Windows
service.  However, now I am interested in distributing my scripts and
want to make it as painless for the end user as possible (hands-off is
best :).  How can you go about running a Python app as a Windows
service without SRVANY?


Pick up a copy of Mark Hammond's book "Python on Win32".  It has an excellent 
chapter on using Win32 extensions to write Windows Services.  Also you might 
consider looking at gmane.comp.python.windows usergroup.


-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-21 Thread Derek Martin
On Sat, Jul 19, 2008 at 02:56:07AM -0700, Lie wrote:
> government, etc. IBM PC is one of the first computers that ordinary
> people could possess, when IBM-clones appeared on the market, they're
> referred as PCs too because they are Personal Computer, a computer
> that is designed for personal use. 

Just to be clear, this statement is WRONG.  PC-clones were so called
because they were clones of the IBM-PC.  The term is very specific to
IBM-compatible hardware.  

  http://en.wikipedia.org/wiki/Pc_clone

IBM PC compatible computers are those generally similar to the
original IBM PC, XT, and AT. Such computers used to be referred to
as PC clones, or IBM clones since they almost exactly duplicated
all the significant features of the PC, XT, or AT internal design,
facilitated by various manufacturers' ability to legally reverse
engineer the BIOS through cleanroom design.

Wikipedia's article on the personal computer accurately reflects
the multiple meanings of the term, and points out the common usage
to mean a Windows box:

  http://en.wikipedia.org/wiki/Personal_computer

Today a PC may be a desktop computer, a laptop computer or a
tablet computer. The most common operating systems are Microsoft
Windows, Mac OS X and Linux, while the most common microprocessors
are x86 compatible CPUs.  However, the term "PC" is often used
only to refer to computers running Microsoft Windows.

So please stop your whining and get used to the idea that THE REST OF
THE WORLD uses PC to mean a Windows box.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpWskQ7X4hnX.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list

scanf in python

2008-07-21 Thread AMD

Hello,

I often need to parse strings which contain a mix of characters, 
integers and floats, the C-language scanf function is very practical for 
this purpose.
I've been looking for such a feature and I have been quite surprised to 
find that it has been discussed as far back as 2001 but never 
implemented. The recommended approach seems to be to use split and then 
atoi or atof or to use regex and then atoi and atof. Both approaches 
seem to be a lot less natural and much more cumbersome than scanf. If 
python already has a % string operator that behaves like printf, why not 
implement either a %% or << string operator to behave like scanf, use 
could be like the followng:


a, b, c = "%d %f %5c" %% "1 2.0 abcde"

or

a, b, c = "%d %f %5c" << "1 2.0 abcde"

%% is closer to the % operator

<< seems more intuitive to me

either of this methods seems to me much simpler than:

lst = "1 2;0 abcde".split()
a = int(lst[0])
b = float(lst[1])
c = lst[2]

or even worse when using regular expressions to parse such simple input.

I like python because it is concise and easy to read and I really think 
it could use such an operator.


I know this has been discussed before and many times, but all previous 
threads I found seem to be dead and I would like to invite further 
investigation of this topic.


Cheers,

André M. Descombes
--
http://mail.python.org/mailman/listinfo/python-list


Re: Please recommend a RPC system working with twisted.

2008-07-21 Thread Larry Bates

??? wrote:

Hi all,

I'm looking for an RPC system working with twisted.

1. Binary.  I want it run faster than any xml based RPC.

2. Bidirectional.  Unlike  HTTP, on which the client has to poll the
sever for events, the server should "call" the client's method to
notify events.

3. C/Python support.  Part of the system shall be written in C.

4. Could easily integrated  with twisted.

Unfortunately, there seems no such resolution existed.  So maybe I
have to give up some requirements.

---

It would be wonderful if ICE could integrate with twisted!


Twisted Perspective Broker?

-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to create GUI dynamically

2008-07-21 Thread Larry Bates

[EMAIL PROTECTED] wrote:

Hi;

i m working on a project where i need  run time creation of GUI.

i have some no. of entities for which i want checkboxes in front of
them which can be checked/ unchecked by user.

But the problem is that the number and name of entities is not fixed
and it depends on the file which is used as input.

So is there any way to tackle this problem.

By the way ; i use Boa constructor (zope editor) for GUI now.

regards
pawan pundir


All the GUI tookits (Tkinter, wxWindows, QT) allow you to build the GUI 
dynamically.

-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to create GUI dynamically

2008-07-21 Thread Peter Wang
On Jul 21, 8:19 am, [EMAIL PROTECTED] wrote:
> Hi;
>
> i m working on a project where i need  run time creation of GUI.
>
> i have some no. of entities for which i want checkboxes in front of
> them which can be checked/ unchecked by user.
>
> But the problem is that the number and name of entities is not fixed
> and it depends on the file which is used as input.
>
> So is there any way to tackle this problem.
>
> By the way ; i use Boa constructor (zope editor) for GUI now.
>
> regards
> pawan pundir

You should check out Traits and Traits UI:
http://code.enthought.com/projects/traits/examples.php

It allows you to dynamically create views and UIs in an easy,
declarative manner.  It is also powerful enough to build much more
complex interactions and dialogs.  It currently supports both WX and
Qt toolkits.

-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread Marc 'BlackJack' Rintsch
On Mon, 21 Jul 2008 17:06:03 +0100, Tim Golden wrote:

> mk wrote:
>
>> Wrong! Real programmers can program using only Touring machine
> 
> Is that some kind of bicycle?

Maybe it's a Turing machine after Bicycle Repair Man got his hands on it!?

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Written in C?

2008-07-21 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>,
 Erik Max Francis <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] wrote:
> 
> > I'm just learning about Python now and it sounds interesting. But I
> > just read (on the Wiki page) that mainstream Python was written in C.
> > That's what I was searching for: Python was written in what other
> > language?
> > 
> > See, my concern was something like: OK, if Python is so hot, then,
> > hopefully someone is writing it in assembly language for each MPU chip
> > out there. Otherwise, if, say, they've written it in C#, then it looks
> > like the REAL, generally useful language to learn is C# and Python is
> > akin to Visual Basic or something: a specialty languagewhereas
> > REAL WORLD programmers who want to be generally useful go and learn
> > C#.
> 
> Psst.  What language do you think the primary implementations of C# is 
> written in?

I know, I know, call on me!

Object Pascal, obviously.

-- 
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >