Re: How much introspection is implementation dependent?

2007-02-03 Thread James Stroud
George Sakkis wrote:
> On Feb 2, 6:56 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> 
>> Hello,
>>
>> I wanted to automagically generate an instance of a class from a
>> dictionary--which might be generated from yaml or json. I came up with this:
>>
>> (snip)
>>
>> ==
>>
>> #! /usr/bin/env python
>>
>> # automagical constructor
>> def construct(cls, adict):
>>dflts = cls.__init__.im_func.func_defaults
>>vnames = cls.__init__.im_func.func_code.co_varnames
>>
>>argnames = vnames[1:-len(dflts)]
>>argvals = [adict.pop(n) for n in argnames]
>>
>>return cls(*argvals, **adict)
>>
>> def test():
>>
>>class C(object):
>>  def __init__(self, arg1, arg2, kwa3=3):
>>self.argsum = arg1 + arg2
>>self.kwsum = kwa3
>>  def __str__(self):
>>return "%s & %s" % (self.argsum, self.kwsum)
>>
>># now a dict for autmagical generation
>>adict = {'arg1':1, 'arg2':2, 'kwa3':42}
>>
>>print ' test 1 '
>>print adict
>>print construct(C, adict)
>>
>>adict = {'arg1':1, 'arg2':2}
>>print
>>print ' test 2 '
>>print adict
>>print construct(C, adict)
>>
>> if __name__ == "__main__":
>>test()
> 
> What's the point of this ? You can call C simply by C(**adict). Am I
> missing something ?
> 
> George
> 

Maybe there is something wrong with my python.

py> class C:
...   def __init__(a, b, c=4):
... print a,b,c
...
py> C(**{'a':10, 'b':5, 'c':4})
Traceback (most recent call last):
   File "", line 1, in 
TypeError: __init__() got multiple values for keyword argument 'a'


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


Re: How much introspection is implementation dependent?

2007-02-03 Thread James Stroud
George Sakkis wrote:
> On Feb 2, 6:56 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> 
>> Hello,
>>
>> I wanted to automagically generate an instance of a class from a
>> dictionary--which might be generated from yaml or json. I came up with this:
>>
>> (snip)
>>
>> ==
>>
>> #! /usr/bin/env python
>>
>> # automagical constructor
>> def construct(cls, adict):
>>dflts = cls.__init__.im_func.func_defaults
>>vnames = cls.__init__.im_func.func_code.co_varnames
>>
>>argnames = vnames[1:-len(dflts)]
>>argvals = [adict.pop(n) for n in argnames]
>>
>>return cls(*argvals, **adict)
>>
>> def test():
>>
>>class C(object):
>>  def __init__(self, arg1, arg2, kwa3=3):
>>self.argsum = arg1 + arg2
>>self.kwsum = kwa3
>>  def __str__(self):
>>return "%s & %s" % (self.argsum, self.kwsum)
>>
>># now a dict for autmagical generation
>>adict = {'arg1':1, 'arg2':2, 'kwa3':42}
>>
>>print ' test 1 '
>>print adict
>>print construct(C, adict)
>>
>>adict = {'arg1':1, 'arg2':2}
>>print
>>print ' test 2 '
>>print adict
>>print construct(C, adict)
>>
>> if __name__ == "__main__":
>>test()
> 
> What's the point of this ? You can call C simply by C(**adict). Am I
> missing something ?
> 
> George
> 

Never mind. You're right.

py> class C(object):
...   def __init__(self, a, b, c=4):
... print a,b,c
...
py> C(**adict)
10 5 4
<__main__.C object at 0x762530>


I guess I thought that, were it this easy, it would have been done in pyaml.

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


How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread John Nagle
   How do I suppress "DeprecationWarning: Old style callback, use cb_func(ok, 
store) instead".  A library is triggering this message, the library is being
fixed, but I need to make the message disappear from the output of a CGI
program.

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


nokia pys60 contacts + calendar

2007-02-03 Thread worlman385
anyone could give a hint on adding new entry to nokia phone's contact
list and calendar 

what function in pys60 python modules would make this working 

or any examples on how to make this work 
 
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where Does One Begin?

2007-02-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> pygame is probily a good program to start with as long as you keep in
> mind that it is possible that up to 50% of the p.c. laptops may not be
> able to run it.

Huh?  Care to explain this?

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


Re: Can a jet fuel/hydrocarbon fire collapse a steel structure? An experiment.

2007-02-03 Thread John Barrett

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Feb 2, 10:32 pm, "John Barrett" <[EMAIL PROTECTED]> wrote:
>> <[EMAIL PROTECTED]> wrote in message
>
>> >> > [snip]
>> >> > Run your "experiment" again but  add some pure oxygen such as was
>> >> > escaping from the on-board breathing oxygen tanks on the
>> >> > airplanes that were crashed into the WTC.
>>
>> > No need to do it. We have the pictures of live humans waving from the
>> > gaping holes in the towers where the planes crashed. We have the
>> > testimonies of the fire fighters that the fires were not that hot and
>> > minor. The fuel of the plane which is mainly in the wings were severed
>> > outside the netting and much of them burnt outside in the fireball
>> > that is visible in all the videos. Futhermore, the black soot that was
>> > visible to the naked eye is indicative of bloody cold flame. Also, the
>> > probability of the oxygen tanks oriented in such a way to inject
>> > oxygen onto the steel as in a oxygen cutting torch is extremely low.
>> > These cylinders have a 1000-3000psi of pressure which makes them into
>> > a rocket or an explosive under uncontrolled gas release. And they
>> > would not contaminate the molten metal with any sulfur. Either the
>> > atmosphere inside was oxidising or reducing. If it was oxidising, how
>> > did the sulfur in huge quantities contaminate the molten metal pools?
>> > The official lies to explain sulfur is from the plaster wall. But that
>> > requires a reducing atmosphere with finely divided and intimately
>> > mixed reactants in a calciner where they are continuously rotated and
>> > run for several hours. Yet the fires ran not even for an hour before
>> > the building collapsed.
>>
>> OK - given all that -- you are left with only one conclusion (or at least 
>> I
>> am) -- progressive structural failure, the loss of support where the 
>> plane
>> hit was sufficient to put excessive stress on the remaining structural
>> members, resulting in a catastrophic sequential failure
>
> I dont think you have seen any actual structural failures, esp
> progressive.
> That happens often in earthquake and they have stacked floors. There
> is
> famous picture of an earthquake on these websites and in the videos.
> Futhermore
> due to erratic stops and goes in the progressive failure, the
> structure falls on the side esp a big bldg like WTC1&2 should have
> fallen from the tipping torque to one side. That did not happen. only
> controlled demolition bldgs fall down straight.
>
>> -- it doesnt take
>> exotic chemical mixes to put excessive mechanical stress on a system... 
>> just
>> chop out enough supports.. it may take time for the remaining supports to
>> deform enough to reach the failure point.. but they will get there, as
>> demonstrated -- occams razor dude -- the least hypothesis is usually the
>> right one -- and I get enough conspiracy theory crap out of my dad --  
>> makes
>> a good movie -- but doesnt pan out in real life -- too many 
>> whistle-blowers
>> around !!
>
> Occams razor is applicable to nature's works. human works are not
> amenable to it. Besides, the official fairy tale is the conspiracy
> theory.
>
>> The city I live in is installing those red-light cameras to catch
>> light-runners -- my dad likes to claim that they manipulate the yellow 
>> time
>> to catch people in the intersection and increase revenue from traffic
>> tickets -- I told him to shut up until he got out there with a stop watch
>> and proved it -- and I say the same to you -- PROVE it -- then make some
>> noise -- conjecture and conspiracy theories without proof are a waste of
>> everyones time. -- how do you know the sulphur was in large quantities ??
>> did you do a chemical analysis ?? or can you produce one done by a 
>> reputable
>> metalurgy company ??
>
> These pillars are not machinable steel. the sulfur here was excessive.
> we are talking about intergranular corrosion, not that teeny amount
> used for imparting machinability and that is not nowadays needed. It
> only for cheap and rough chinese type crap and i am not sure even
> there if someone would ruin their steel mills by adding this kind of
> corrosive sulfur shit. come on dude ... dont mix categories.
>
>> Ohhh and by the way -- high sulphur steels are regularly used for 
>> machined
>> components -- was the amount of sulphur detected incosistent with what 
>> may
>> have been present due to the use of high sulphur steels ?? (where is that
>> metalurgy report again ??)
>
> yeah a damn fool would put sulfur in the bolts and load bearing
> elements such as the bolts of aircrafts and space shuttle.
>
> Besides how do you explain the completely pulverized building ??
> if not for explosives.
>
>

I just proposed a theory -- structural failure -- as plausible as yours and 
much more likely

completely pulverized -- I would expect so with god knows how many tons of 
steel and concrete falling from a height of 100s of feet -- lotsa energ

Regd. Regular expressions PyQt

2007-02-03 Thread vishal
Hello All:
I am trying to work out a regular expression in a PyQt environment for
time in hh:mm:ss format. Any suggestions?
Thanks,
Vishal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Build Python 2.5 wit VC6.0 ?

2007-02-03 Thread Martin v. Löwis
Alexander Eisenhuth schrieb:
> does somebody have experience in building with VC6.0. On my first try
> there where missing C-Modules. Is that true. VC6.0 is not supported?

It is supported, but not actively maintained. Contributions are welcome.
Try the 2.5 maintenance branch first, though; it may have fixed your
problem.

> PC: What Python version supports VC6.0?

The last version where the official Windows binaries were built with
VC6 was Python 2.3.

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


Re: main

2007-02-03 Thread Ben Finney
[EMAIL PROTECTED] writes:

> is the main function in python is exact compare to Java main method?
> all execution start in main which may takes arguments?

There's no such thing in Python; a module is executed sequentially,
with no particular regard to the names of any of the attributes.

There is, though, a convention of writing a module that can be either
imported or executed as a program, by testing inside the module
whether the current module name is the magic string "__main__".

=== foo.py ===
# This code is executed whether or not this module is the main module
print "Module foo.py is running with name:", __name__

if __name__ == '__main__':
# This block is executed only if the module is the main program module
print "Module foo.py is the main program"
=== foo.py ===

=== bar.py ===
import foo

print "Module bar.py is running with name:", __name__
=== bar.py ===

=
$ python ./foo.py   # Run foo.py as a program
Module foo.py is running with name: __main__
Module foo.py is the main program

$ python ./bar.py   # Run bar.py as a program, which imports foo.py as a 
module
Module foo.py is running with name: foo
Module bar.py is running with name: __main__
=

That allows the following idiom:

> if __name__ == "__main__":
> sys.exit( main(sys.argv) )

All the rest of the code is executed whether or not the program is the
main module; but right at the end, after defining all the attributes
and functions and classes etc., this test says *if* this module is the
main program, then *also* execute the "main" function (and then exit
Python with the return value from that function).

The benefit of this is that this module, designed to be run as a
program, is *also* designed to be imported by other programs so that
its functions etc. can be used as required, *without* necessarily
running the main function.

-- 
 \  "If I haven't seen as far as others, it is because giants were |
  `\standing on my shoulders."  -- Hal Abelson |
_o__)  |
Ben Finney

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


Re: main

2007-02-03 Thread Gabriel Genellina
En Sat, 03 Feb 2007 02:37:11 -0300, Paddy <[EMAIL PROTECTED]>  
escribió:

>> and what is
>> __name__
>> __main__
>>
>> use for in terms of Java?
>>
>
> With respect, (hehe), maybe you need to indicate that you've searched
> the Python documentation on __name__ and __main__?
> (Hah! I did that without saying RTFM. - Oh pooh! Fiddlesticks).

Have you acually tried to do the search? The Python tutorial doesn't  
menction that at all. And no one should expect that a beginner would have  
to read section 26.3 on the Language Reference (__main__ -- Top-level  
script environment) just to know what's that stuff about __name__  and  
"__main__"...

-- 
Gabriel Genellina

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


Re: from __future__ import absolute_import ?

2007-02-03 Thread Peter Otten
Ron Adam wrote:

> Peter Otten wrote:
>> Ron Adam wrote:
>> 
>>> from __future__ import absolute_import
>>>
>>> Is there a way to check if this is working?  I get the same results with
>>> or without it.
>>>
>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
>>> [MSC v.1310 32 bit (Intel)] on win 32
>> 
>> If there are two modules 'foo', one at the toplevel and the other inside
>> a package 'bar',
>> 
>> from __future__ import absolute_import
>> import foo
>> 
>> will import the toplevel module whereas
>> 
>> import foo
>> 
>> will import bar.foo. A messy demonstration:
>> 
>> $ ls bar
>> absolute.py  foo.py  __init__.py  relative.py
>> $ cat bar/absolute.py
>> from __future__ import absolute_import
>> import foo
>> $ cat bar/relative.py
>> import foo
>> $ cat foo.py
>> print "toplevel"
>> $ cat bar/foo.py
>> print "in bar"
>> $ python2.5 -c 'import bar.absolute'
>> toplevel
>> $ python2.5 -c 'import bar.relative'
>> in bar
>> 
>> 
>> Another example is here:
>> 
>> http://mail.python.org/pipermail/python-list/2007-January/422889.html
>> 
>> Peter
> 
> Thanks, that helped, I see why I was having trouble.
> 
> 
> work
>   |
>   |- foo.py# print "foo not in bar"
>   |
>   `- bar
>   |
>   |- __init__.py
>   |
>   |- foo.py# print "foo in bar"
>   |
>   |- absolute.py   # from __futer__ import absolute_import
>   |# import foo
>   |
>   `- relative.py   # import foo
> 
> 
> * Where "work" is in the path.
> 
> 
> (1)
> 
> C:\work>python -c "import bar.absolute"
> foo not in bar
> 
> C:\work>python -c "import bar.relative"
> foo in bar
> 
> 
> (2)
> 
> C:\work>python -m "bar.absolute"
> foo not in bar
> 
> C:\work>python -m "bar.relative"
> foo not in bar
> 
> 
> (3)
> 
> C:\work>python
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
> on win 32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import bar.absolute
> foo not in bar
>  >>> import bar.relative
> foo in bar
> 
> 
> (4)
> 
> C:\work>cd bar

A path below the package level is generally a good means to shoot yourself
in the foot and should be avoided with or without absolute import.
 
> C:\work\bar>python -c "import bar.absolute"
> foo in bar
> 
> C:\work\bar>python -c "import bar.relative"
> foo in bar
> 
> 
> (5)
> 
> C:\work\bar>python
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
> on win 32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import bar.absolute
> foo in bar
>  >>> import bar.relative
> foo in bar
>  >>>
> 
> 
> 
> Case (2) seems like it is a bug.

I think so, too.
 
> Why not also have (4), and (5) do the same as cases (1) and (3)?

The work/bar directory is the current working directory and occurs in the
path before the work directory. When bar.absolute imports foo python is
unaware that work/bar/foo.py is part of the bar package.

> in cases (4) and (5), that is the result I would expect if I did:
> 
> import absolute   # with no 'bar.' prefix.
> import relative
> 
> 
>  From what I understand, in 2.6 relative imports will be depreciated, and
>  in 2.7
> they will raise an error.  (providing plans don't change)
> 
> Would that mean the absolute imports in (4) and (5) would either find the
> 'foo not in bar' or raise an error?

No, in 1, 3 -- and 2 if the current behaviour is indeed a bug. This is only
for the relative import which would have to be spelt

from . import foo

in an absolute-import-as-default environment;

import foo

would always be an absolute import.

> If so, is there any way to force (warning/error) behavior now?

I don't know.

Peter

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


Re: Regd. Regular expressions PyQt

2007-02-03 Thread Paddy
On Feb 3, 8:24 am, [EMAIL PROTECTED] wrote:
> Hello All:
> I am trying to work out a regular expression in a PyQt environment for
> time in hh:mm:ss format. Any suggestions?
> Thanks,
> Vishal

Yep,
Use Kodos!
http://kodos.sourceforge.net/

- It's Fab.

- Paddy.

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


Re: Python does not play well with others

2007-02-03 Thread Ben Finney
Paul Rubin <"http://phr.cx"@NOSPAM.invalid> writes:

> Since Python is being touted as good for web apps as a competitor to
> PHP

Python is being touted as a good language for *many* purposes, not
just web applications. Python is also a "competitor" to Java, to Ruby,
to Perl, to many other languages. They all have strengths and
weaknesses.

> it should offer the same db connectivity in its stdlib that PHP
> offers in its.

That doesn't follow at all. Many consider the humungous function
library of PHP to be a significant downside of the system, which
criterion leaves Python ahead. More is not necessarily better.

> I'm paying the hosting company for access to a computer that's
> connected to electricity and to the internet and which has a
> straightforward OS, language package, web server, and db installed.

In which case, there should be no problem with *you* installing
whatever software you need to use the system for what you want.

> They shouldn't have to deal with dozens of interdependent modules
> downloaded from different places just to support one language.

Either they are providing far more than the minimal set you describe
above, or this is entirely outside their domain. Make up your mind.

You can't claim both that the hosting company should have to maintain
a comprehensive set of functionality, *and* that they should not have
to.

-- 
 \   "Don't worry about what anybody else is going to do. The best |
  `\  way to predict the future is to invent it."  -- Alan Kay |
_o__)  |
Ben Finney

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


Regd. Kodos

2007-02-03 Thread vishal
I am trying to use Kodos..but not getting thru'..dont know whats goin
on..does anyone have a regular expression for time in hh:mm:ss
-Vishal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can a jet fuel/hydrocarbon fire collapse a steel structure? An experiment.

2007-02-03 Thread John Barrett

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Feb 2, 10:32 pm, "John Barrett" <[EMAIL PROTECTED]> wrote:
>> <[EMAIL PROTECTED]> wrote in message
>
>> >> > [snip]
>> >> > Run your "experiment" again but  add some pure oxygen such as was
>> >> > escaping from the on-board breathing oxygen tanks on the
>> >> > airplanes that were crashed into the WTC.
>>
>> > No need to do it. We have the pictures of live humans waving from the
>> > gaping holes in the towers where the planes crashed. We have the
>> > testimonies of the fire fighters that the fires were not that hot and
>> > minor. The fuel of the plane which is mainly in the wings were severed
>> > outside the netting and much of them burnt outside in the fireball
>> > that is visible in all the videos. Futhermore, the black soot that was
>> > visible to the naked eye is indicative of bloody cold flame. Also, the
>> > probability of the oxygen tanks oriented in such a way to inject
>> > oxygen onto the steel as in a oxygen cutting torch is extremely low.
>> > These cylinders have a 1000-3000psi of pressure which makes them into
>> > a rocket or an explosive under uncontrolled gas release. And they
>> > would not contaminate the molten metal with any sulfur. Either the
>> > atmosphere inside was oxidising or reducing. If it was oxidising, how
>> > did the sulfur in huge quantities contaminate the molten metal pools?
>> > The official lies to explain sulfur is from the plaster wall. But that
>> > requires a reducing atmosphere with finely divided and intimately
>> > mixed reactants in a calciner where they are continuously rotated and
>> > run for several hours. Yet the fires ran not even for an hour before
>> > the building collapsed.
>>
>> OK - given all that -- you are left with only one conclusion (or at least 
>> I
>> am) -- progressive structural failure, the loss of support where the 
>> plane
>> hit was sufficient to put excessive stress on the remaining structural
>> members, resulting in a catastrophic sequential failure
>
> I dont think you have seen any actual structural failures, esp
> progressive.
> That happens often in earthquake and they have stacked floors. There
> is
> famous picture of an earthquake on these websites and in the videos.
> Futhermore
> due to erratic stops and goes in the progressive failure, the
> structure falls on the side esp a big bldg like WTC1&2 should have
> fallen from the tipping torque to one side. That did not happen. only
> controlled demolition bldgs fall down straight.
>
>> -- it doesnt take
>> exotic chemical mixes to put excessive mechanical stress on a system... 
>> just
>> chop out enough supports.. it may take time for the remaining supports to
>> deform enough to reach the failure point.. but they will get there, as
>> demonstrated -- occams razor dude -- the least hypothesis is usually the
>> right one -- and I get enough conspiracy theory crap out of my dad --  
>> makes
>> a good movie -- but doesnt pan out in real life -- too many 
>> whistle-blowers
>> around !!
>
> Occams razor is applicable to nature's works. human works are not
> amenable to it. Besides, the official fairy tale is the conspiracy
> theory.
>
>> The city I live in is installing those red-light cameras to catch
>> light-runners -- my dad likes to claim that they manipulate the yellow 
>> time
>> to catch people in the intersection and increase revenue from traffic
>> tickets -- I told him to shut up until he got out there with a stop watch
>> and proved it -- and I say the same to you -- PROVE it -- then make some
>> noise -- conjecture and conspiracy theories without proof are a waste of
>> everyones time. -- how do you know the sulphur was in large quantities ??
>> did you do a chemical analysis ?? or can you produce one done by a 
>> reputable
>> metalurgy company ??
>
> These pillars are not machinable steel. the sulfur here was excessive.
> we are talking about intergranular corrosion, not that teeny amount
> used for imparting machinability and that is not nowadays needed. It
> only for cheap and rough chinese type crap and i am not sure even
> there if someone would ruin their steel mills by adding this kind of
> corrosive sulfur shit. come on dude ... dont mix categories.
>
>> Ohhh and by the way -- high sulphur steels are regularly used for 
>> machined
>> components -- was the amount of sulphur detected incosistent with what 
>> may
>> have been present due to the use of high sulphur steels ?? (where is that
>> metalurgy report again ??)
>
> yeah a damn fool would put sulfur in the bolts and load bearing
> elements such as the bolts of aircrafts and space shuttle.
>
> Besides how do you explain the completely pulverized building ??
> if not for explosives.
>
>

have your read THIS ??


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


Re: python bracket

2007-02-03 Thread Gabriel Genellina
En Sat, 03 Feb 2007 02:48:45 -0300, <[EMAIL PROTECTED]> escribió:

> there is no bracket in python
>
> how can i know where a loop or a function ends?

You should read some introductory texts at least.
You can find the Python Tutorial inside your Python install, or you can  
read it online at http://docs.python.org/tut/
The book Dive into Python is also available online at  
http://www.diveintopython.org/

NB: Indentation is important in Python. A block ends when a less indented  
line appears.

-- 
Gabriel Genellina

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


Re: main

2007-02-03 Thread Paddy
On Feb 3, 8:51 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Sat, 03 Feb 2007 02:37:11 -0300, Paddy <[EMAIL PROTECTED]>
> escribió:
>
> >> and what is
> >> __name__
> >> __main__
>
> >> use for in terms of Java?
>
> > With respect, (hehe), maybe you need to indicate that you've searched
> > the Python documentation on __name__ and __main__?
> > (Hah! I did that without saying RTFM. - Oh pooh! Fiddlesticks).
>
> Have you acually tried to do the search? The Python tutorial doesn't
> menction that at all. And no one should expect that a beginner would have
> to read section 26.3 on the Language Reference (__main__ -- Top-level
> script environment) just to know what's that stuff about __name__  and
> "__main__"...
>
> --
> Gabriel Genellina

Good point.
Googling for :
  tutorial "if __name__ = '__main__'"
  http://www.google.co.uk/search?hl=en&safe=off&q=tutorial+%22if
+__name__+%3D+%27__main__%27%22&btnG=Search&meta=
Gives this excellent page by the effbot:
  http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm

In fact, fatwallet should add its index page to his bookmarks:
  http://effbot.org/pyfaq/

Thanks Gabriel,
- Paddy.

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


Re: Can a jet fuel/hydrocarbon fire collapse a steel structure? An experiment.

2007-02-03 Thread John Barrett

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Feb 2, 10:32 pm, "John Barrett" <[EMAIL PROTECTED]> wrote:
>> <[EMAIL PROTECTED]> wrote in message
>
>> >> > [snip]
>> >> > Run your "experiment" again but  add some pure oxygen such as was
>> >> > escaping from the on-board breathing oxygen tanks on the
>> >> > airplanes that were crashed into the WTC.
>>
>> > No need to do it. We have the pictures of live humans waving from the
>> > gaping holes in the towers where the planes crashed. We have the
>> > testimonies of the fire fighters that the fires were not that hot and
>> > minor. The fuel of the plane which is mainly in the wings were severed
>> > outside the netting and much of them burnt outside in the fireball
>> > that is visible in all the videos. Futhermore, the black soot that was
>> > visible to the naked eye is indicative of bloody cold flame. Also, the
>> > probability of the oxygen tanks oriented in such a way to inject
>> > oxygen onto the steel as in a oxygen cutting torch is extremely low.
>> > These cylinders have a 1000-3000psi of pressure which makes them into
>> > a rocket or an explosive under uncontrolled gas release. And they
>> > would not contaminate the molten metal with any sulfur. Either the
>> > atmosphere inside was oxidising or reducing. If it was oxidising, how
>> > did the sulfur in huge quantities contaminate the molten metal pools?
>> > The official lies to explain sulfur is from the plaster wall. But that
>> > requires a reducing atmosphere with finely divided and intimately
>> > mixed reactants in a calciner where they are continuously rotated and
>> > run for several hours. Yet the fires ran not even for an hour before
>> > the building collapsed.
>>
>> OK - given all that -- you are left with only one conclusion (or at least 
>> I
>> am) -- progressive structural failure, the loss of support where the 
>> plane
>> hit was sufficient to put excessive stress on the remaining structural
>> members, resulting in a catastrophic sequential failure
>
> I dont think you have seen any actual structural failures, esp
> progressive.
> That happens often in earthquake and they have stacked floors. There
> is
> famous picture of an earthquake on these websites and in the videos.
> Futhermore
> due to erratic stops and goes in the progressive failure, the
> structure falls on the side esp a big bldg like WTC1&2 should have
> fallen from the tipping torque to one side. That did not happen. only
> controlled demolition bldgs fall down straight.
>
>> -- it doesnt take
>> exotic chemical mixes to put excessive mechanical stress on a system... 
>> just
>> chop out enough supports.. it may take time for the remaining supports to
>> deform enough to reach the failure point.. but they will get there, as
>> demonstrated -- occams razor dude -- the least hypothesis is usually the
>> right one -- and I get enough conspiracy theory crap out of my dad --  
>> makes
>> a good movie -- but doesnt pan out in real life -- too many 
>> whistle-blowers
>> around !!
>
> Occams razor is applicable to nature's works. human works are not
> amenable to it. Besides, the official fairy tale is the conspiracy
> theory.
>
>> The city I live in is installing those red-light cameras to catch
>> light-runners -- my dad likes to claim that they manipulate the yellow 
>> time
>> to catch people in the intersection and increase revenue from traffic
>> tickets -- I told him to shut up until he got out there with a stop watch
>> and proved it -- and I say the same to you -- PROVE it -- then make some
>> noise -- conjecture and conspiracy theories without proof are a waste of
>> everyones time. -- how do you know the sulphur was in large quantities ??
>> did you do a chemical analysis ?? or can you produce one done by a 
>> reputable
>> metalurgy company ??
>
> These pillars are not machinable steel. the sulfur here was excessive.
> we are talking about intergranular corrosion, not that teeny amount
> used for imparting machinability and that is not nowadays needed. It
> only for cheap and rough chinese type crap and i am not sure even
> there if someone would ruin their steel mills by adding this kind of
> corrosive sulfur shit. come on dude ... dont mix categories.
>
>> Ohhh and by the way -- high sulphur steels are regularly used for 
>> machined
>> components -- was the amount of sulphur detected incosistent with what 
>> may
>> have been present due to the use of high sulphur steels ?? (where is that
>> metalurgy report again ??)
>
> yeah a damn fool would put sulfur in the bolts and load bearing
> elements such as the bolts of aircrafts and space shuttle.
>
> Besides how do you explain the completely pulverized building ??
> if not for explosives.
>
>

lets try that again :)

http://www.tms.org/pubs/journals/JOM/0112/Eagar/Eagar-0112.html

A very concise and MUCH more believable explanation of the structural 
failure modes involved WITH numbers that MAKE SENSE !! (and interestingly 
enough,

Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread Peter Otten
John Nagle wrote:

>How do I suppress "DeprecationWarning: Old style callback, use
>cb_func(ok,
> store) instead".  A library is triggering this message, the library is
> being fixed, but I need to make the message disappear from the output of a
> CGI program.

import warnings
warnings.filterwarnings("ignore", message="Old style callback, use
cb_func(ok, store) instead")

Peter

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


Re: Regd. Kodos

2007-02-03 Thread Paddy
On Feb 3, 8:59 am, [EMAIL PROTECTED] wrote:
> I am trying to use Kodos..but not getting thru'..dont know whats goin
> on..does anyone have a regular expression for time in hh:mm:ss
> -Vishal

Well, with just knowing the above, the following raw string when used
as a regular expression will capture the hh,mm,ss as groups 1,2,3
r'\b(\d\d):(\d\d):(\d\d)\b'

- Paddy

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


Re: Regd. Kodos

2007-02-03 Thread Paddy
On Feb 3, 9:17 am, "Paddy" <[EMAIL PROTECTED]> wrote:
> On Feb 3, 8:59 am, [EMAIL PROTECTED] wrote:
>
> > I am trying to use Kodos..but not getting thru'..dont know whats goin
> > on..does anyone have a regular expression for time in hh:mm:ss
> > -Vishal
>
> Well, with just knowing the above, the following raw string when used
> as a regular expression will capture the hh,mm,ss as groups 1,2,3
> r'\b(\d\d):(\d\d):(\d\d)\b'
>
> - Paddy

P.S. I fired up Kodos and cut and pasted your message into the search
string box;
left the bottom notebook on the groups tag to show what groups i had
captured; left the flags al off; then started typing the regular
expression into the regular expression pattern box.
Thats when i realised that your email said hh:mm:ss and I needed to
match something with numbers so appended 08:34:66 as a new ine in the
search string box.
After typing in the regex, the group tab showed what I was after

I like Kodos because it helps me when the RE's are much longer but i
have sample text that I can easily paste in. I usually paste in a
large tet sample just to make sure my RE doesn't fail on something I'm
not expecting.
- Paddy.
.

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


Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread Gabriel Genellina
En Sat, 03 Feb 2007 06:12:33 -0300, Peter Otten <[EMAIL PROTECTED]>  
escribió:

> John Nagle wrote:
>
>>How do I suppress "DeprecationWarning: Old style callback, use
>>cb_func(ok,
>> store) instead".  A library is triggering this message, the library is
>> being fixed, but I need to make the message disappear from the output  
>> of a
>> CGI program.
>
> import warnings
> warnings.filterwarnings("ignore", message="Old style callback, use
> cb_func(ok, store) instead")

Or you can be more aggressive and filter out all DeprecationWarnings:
warnings.simplefilter("ignore",DeprecationWarning)
(same as using option -Wignore::DeprecationWarning on the python command  
line)

-- 
Gabriel Genellina

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


pyYaml community

2007-02-03 Thread Imbaud Pierre
I began using pyYaml.
I found no place where pyYaml users exchange ideas, know-how, etc
(as here for python).
There is a wiki, a bug tracker, documentation, but such a place
(mailing list, newsgroup, forum, or even IRC) is a must (IMHO) to smooth 
the learning curve.
Does someone know better?

My concern: yaml allows "complex data" as keys to dicts.
I need tuples as keys, pyYaml turns my yaml sequences into lists,
and then yells list cant be used as keys. No way to turn my yaml 
sequences into tuples?
Oh, I found! RTFM, as usual!
(the first question sticks)
-- 
http://mail.python.org/mailman/listinfo/python-list


Create a cookie with cookielib

2007-02-03 Thread Alessandro Fachin
Hi, i am trying to forge a new cookie by own with cookielib. But i don't
still have success. This a simply code:

import cookielib, urllib, urllib2
login = 'Ia am a cookie!'
cookiejar = cookielib.CookieJar()
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
values = {'user':login}
data = urllib.urlencode(values)
request = urllib2.Request("http://localhost/cookie.php";, data)
url = urlOpener.open(request)
print url.info()
page = url.read(50)
print page
print cookiejar

the output of this is:

Date: Sat, 03 Feb 2007 10:20:05 GMT
Server: Apache
X-Powered-By: PHP/5.1.6
Set-Cookie: user=Alex+Porter; expires=Sat, 03-Feb-2007 11:20:05 GMT
Content-Length: 11
Connection: close
Content-Type: text/html; charset=UTF-8

Array
(
)
]>

And here is the code of cookie.php that i've create for this example:




if anyone could help... Thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread Neil Cerutti
On 2007-02-03, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Sat, 03 Feb 2007 06:12:33 -0300, Peter Otten <[EMAIL PROTECTED]>  
> escribió:
>
>> John Nagle wrote:
>>
>>>How do I suppress "DeprecationWarning: Old style callback, use
>>>cb_func(ok,
>>> store) instead".  A library is triggering this message, the library is
>>> being fixed, but I need to make the message disappear from the output  
>>> of a
>>> CGI program.
>>
>> import warnings
>> warnings.filterwarnings("ignore", message="Old style callback, use
>> cb_func(ok, store) instead")
>
> Or you can be more aggressive and filter out all DeprecationWarnings:
> warnings.simplefilter("ignore",DeprecationWarning)
> (same as using option -Wignore::DeprecationWarning on the python command  
> line)

Ah, yes! The null module. Python should have more of these. I
mean "shouldn't". ;)

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


Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread Peter Otten
Gabriel Genellina wrote:

> En Sat, 03 Feb 2007 06:12:33 -0300, Peter Otten <[EMAIL PROTECTED]>
> escribió:
> 
>> John Nagle wrote:
>>
>>>How do I suppress "DeprecationWarning: Old style callback, use
>>>cb_func(ok,
>>> store) instead".  A library is triggering this message, the library is
>>> being fixed, but I need to make the message disappear from the output
>>> of a
>>> CGI program.
>>
>> import warnings
>> warnings.filterwarnings("ignore", message="Old style callback, use
>> cb_func(ok, store) instead")
> 
> Or you can be more aggressive and filter out all DeprecationWarnings:
> warnings.simplefilter("ignore",DeprecationWarning)
> (same as using option -Wignore::DeprecationWarning on the python command
> line)

The latter might be interesting for a cgi. I didn't mention it because I
didn't get it to work with my test case (importing sre) and Python's cgi
server. Trying again, I found that you must not quote the -W argument.

#!/usr/local/bin/python2.5 -Wignore:The sre module is deprecated, please
import re. 

>From that follows that you can pass at most one commandline arg. 
If you are using 

#!/usr/bin/env python2.5

python2.5 will be that single argument and no options are possible at all.
What might be the reasons for such a seemingly arbitrary limitation?

Peter

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


Re: nokia pys60 contacts + calendar

2007-02-03 Thread cyberco
You can most likely find an answer on Nokia's Python forum:
http://discussion.forum.nokia.com/forum/forumdisplay.php?f=102

And if there's no answer there you should post the question there :)

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


wxPython: TextCtrl delayed update when using TE_RICH(2)

2007-02-03 Thread citronelu
I made a small wxPython app that retrieves web data; for visual
logging I use a TextCtrl widget, and stdout is redirected to it,
something like this:

class RedirectOutput:
def __init__(self, objectTxtCtrl):
self.out = objectTxtCtrl

def write(self, string):
self.out.WriteText(string)

[...]

messages = wx.TextCtrl(panel, -1, "", size = (-1, 200), style =
wx.TE_MULTILINE | wx.TE_RICH, name = "messages")

myout = RedirectOutput(messages)
sys.stdout = myout


The web query is inside a function (def Execute), binded to a button.
To simplify the story, consider the function looks like this:

def Execute(self, evt):
print "Start query"
time.sleep(5)

The "Start query" message should show in the *messages* box when I
press the button. Instead, it shows only after the time.sleep(5)
delay.

If I don't use the wx.TE_RICH / wx.TE_RICH2 style on *messages*, the
text shows before the time.sleep(5)

I want to use wx.TE_RICH / wx.TE_RICH2 because of the 64k limitation
of the standard TextCtrl.

I'm using python 2.4.3 and wxpython 2.8.1.1 unicode, on WinXP SP2.
Windows extensions are also installed.

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


HELP NEEDED ... Regd. Regular expressions PyQt

2007-02-03 Thread vishal
Hello All:
I am trying to work out a regular expression in a PyQt environment for
time in hh:mm:ss format. Any suggestions?
Thanks,
Vishal


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


Re: HELP NEEDED ... Regd. Regular expressions PyQt

2007-02-03 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hello All:
> I am trying to work out a regular expression in a PyQt environment for
> time in hh:mm:ss format. Any suggestions?

Yes. Read the manual to the re-module. There is _nothing_ special about 
PyQt and regexes. And provide code. But the most important thing - read 
this:


http://www.catb.org/~esr/faqs/smart-questions.html

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


Python 2.5 Quick Reference

2007-02-03 Thread Dick Moores

Is this reliable? (Looks good to me, but...)

Thanks,

Dick Moores


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


Re: compound statement from C "?:"

2007-02-03 Thread Jussi Salmela
[EMAIL PROTECTED] kirjoitti:
> Jussi Salmela:
>> In this particular case you don't need the ternary operator:
>> print "I saw %d car%s\n" % (n, ("", "s")[n != 1])
> 
> The last newline is probably unnecessary. This seems be a bit more
> readable:
> print "I saw", n, "car" + ("", "s")[n != 1]
> 
> With Python 2.5 this looks better:
> print "I saw", n, "car" + ("" if n == 1 else "s")
> 
> Or the vesion I like better:
> print "I saw", n, ("car" if n == 1 else "cars")
> 
> Those () aren't necessary, but they help improve readability, and
> avoid problems with operator precedence too. That if has a quite low
> precedence.
> 
> Bye,
> bearophile
> 
This is getting weird but here's 2 more in the spirit of
"who needs the ternary operator - I don't!". And I'm starting to
wonder what the 'obvious way' (as in 'Zen of Python') to write
this would be.

print "I saw %d car%s" % (n, {1:''}.get(n==1, 's'))

print "I saw %d car%s" % (n, 's'*(n!=1))

Cheers,
Jussi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5 Quick Reference

2007-02-03 Thread Robin Becker
Dick Moores wrote:
> 
> Is this reliable? (Looks good to me, but...)
> 
.

I really like these for a good overview
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where Does One Begin?

2007-02-03 Thread Michael
George Sakkis wrote:

> On Feb 2, 3:39 pm, Mister Newbie <[EMAIL PROTECTED]> wrote:
> 
>> I have no programming experience. I want to learn Python so I can make
>> simple, 2D games. Where should I start? Can you recommend a good book?
>>
>> Thank you.
> 
> http://www.amazon.com/Game-Programming-Python-Development/dp/1584502584

It's a nice book, but totally inappropriate in my opinion for someone who
says they have no programming experience.


Michael.

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


Re: Where Does One Begin?

2007-02-03 Thread Michael
Marc 'BlackJack' Rintsch wrote:

> In <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] wrote:
> 
>> pygame is probily a good program to start with as long as you keep in
>> mind that it is possible that up to 50% of the p.c. laptops may not be
>> able to run it.
> 
> Huh?  Care to explain this?

I'd appreciate that being explained as well (also preferably backed up as
well, but I'd be happy with explained :), since I've not actually seen this
problem myself ever, though I've heard about it occasionally, but never
seen it. What causes the problem?

Michael.

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


Re: Find and replace in a file with regular expression

2007-02-03 Thread Frederic Rentsch
TOXiC wrote:
> Hi everyone,
> First I say that I serched and tryed everything but I cannot figure 
> out how I can do it.
> I want to open a a file (not necessary a txt) and find and replace a 
> string.
> I can do it with:
>
> import fileinput, string, sys
> fileQuery = "Text.txt"
> sourceText = '''SOURCE'''
> replaceText = '''REPLACE'''
> def replace(fileName, sourceText, replaceText):
>
> file = open(fileName, "r")
> text = file.read() #Reads the file and assigns the value to a 
> variable
> file.close() #Closes the file (read session)
> file = open(fileName, "w")
> file.write(text.replace(sourceText, replaceText))
> file.close() #Closes the file (write session)
> print "All went well, the modifications are done"
>
> replacemachine(fileQuery, sourceText, replaceText)
>
> Now all went ok but I'm wondering if it's possible to replace text if /
> sourceText/ match a regex.
> Help me please!
> Thx in advance
>
>   
Try this:

 >>> import SE   # from http://cheeseshop.python.org/pypi/SE/2.3

 >>> replacements = 'SOURCE=REPLACE "another source=another replace" 
~[0-9]+~=>>int<< ~[0-9]+\\.[0-9]+~=>>float<<  ~'
# Define as many replacements as you like. Identify regexes placing 
them between '~'

 >>> Stream_Editor = SE.SE (replacements)

 >>> Stream_Editor (input_file, output_file)

That's it.


PS 1: Your Stream_Editor accepts strings as well as file names and then 
returns a string by default. This is a great help for developing 
substitution sets interactively.

 >>> print Stream_Editor ('''
If it works, this SOURCE should read REPLACE
and another source should become another replace
and this 123456789 should become >>int<<
and this 12345.6789 is a float and so should read >>float<<.''')

If it works, this REPLACE should read REPLACE
and another replace should become another replace
and this >>int<< should become >>int<<
and this >>float<< is a float and so should read >>float<<.

PS 2: It is convenient to keep large and frequently used substitution 
sets in text files. The SE constructor accepts a file name instead of 
the replacements string:

 >>> Stream_Edtor = SE.SE ('path/replacement_definitions_file')


Regards

Frederic





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


Vim scripting with python

2007-02-03 Thread Tool69
Hi,

I saw several old posts speaking of vim scripting in Python. This one
in particular :
http://www.velocityreviews.com/forums/t351303-re-pythonising-the-vim-eg-syntax-popups-gt-vimpst.html

But I didn't find where to put this "vimrc.py" on my Windows machine.
My "normal" _vimrc file is in C:\Documents and Settings\my_name .

Does anyone have any advice, and more genraly how to script Vim with
Python ?

I know I can put some python functions inside my vimrc file like
this :

function! My_function()
python << EOF
import vim, string
...blablabla
EOF
endfunction

but I would like to use external ".py" files.

Thanks.

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


Re: Python 2.5 Quick Reference

2007-02-03 Thread Dick Moores
At 04:02 AM 2/3/2007, Robin Becker wrote:
>Dick Moores wrote:
> > 
> > Is this reliable? (Looks good to me, but...)
> >
>.
>
>I really like these for a good overview

So it looks accurate?

Dick Moores

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


strange test for None

2007-02-03 Thread karoly.kiripolszky
in my server i use the following piece of code:

ims = self.headers["if-modified-since"]
if ims != None:
t = int(ims)

and i'm always getting the following error:

t = int(ims)
ValueError: invalid literal for int(): None

i wanna know what the hell is going on... first i tried to test using
is not None, but it makes no difference.

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


strange test for None

2007-02-03 Thread karoly.kiripolszky
in my server i use the following piece of code:

ims = self.headers["if-modified-since"]
if ims != None:
t = int(ims)

and i'm always getting the following error:

t = int(ims)
ValueError: invalid literal for int(): None

i wanna know what the hell is going on... first i tried to test using
is not None, but it makes no difference.

sorry i forgot, it's interpreter 2.4.4.

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


Re: strange test for None

2007-02-03 Thread karoly.kiripolszky
forgot to mention my interpreter version: 2.4.4

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


Re: Python 2.5 Quick Reference

2007-02-03 Thread skip
Dick> 

Respondent> I really like these for a good overview

Dick> So it looks accurate?

He's been doing it awhile:

http://rgruet.free.fr/

I think he's got the drill down pretty well by now... ;-)

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


Re: Python 2.5 Quick Reference

2007-02-03 Thread Peter Otten
Dick Moores wrote:

> At 04:02 AM 2/3/2007, Robin Becker wrote:
>>Dick Moores wrote:
>> > 
>> > Is this reliable? (Looks good to me, but...)
>> >
>>.
>>
>>I really like these for a good overview
> 
> So it looks accurate?

After perusing it, I dare say that not only is it accurate, Richard's
comments seem both at the right places and spot-on.

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


Re: strange test for None

2007-02-03 Thread skip
> "karoly" == karoly kiripolszky  writes:

karoly> in my server i use the following piece of code:
karoly> ims = self.headers["if-modified-since"]
karoly> if ims != None:
karoly> t = int(ims)

karoly> and i'm always getting the following error:

karoly> t = int(ims)
karoly> ValueError: invalid literal for int(): None

Try printing repr(ims), type(ims) and id(ims) then compare that with
repr(None), type(None) and id(None).   My guess is you have a string whose
value is "None":

% python2.4
Python 2.4.1 (#3, Jul 28 2005, 22:08:40) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1671)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> int("None")
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: invalid literal for int(): None

The output in 2.5 makes it more clear what you've got:

% python2.5
Python 2.5c1 (release25-maint:51339, Aug 17 2006, 22:15:14) 
[GCC 4.0.0 (Apple Computer, Inc. build 5026)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
in>>> int("None")
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid literal for int() with base 10: 'None'

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


Re: compound statement from C "?:"

2007-02-03 Thread Peter Otten
Jussi Salmela wrote:

> [EMAIL PROTECTED] kirjoitti:
>> Jussi Salmela:
>>> In this particular case you don't need the ternary operator:
>>> print "I saw %d car%s\n" % (n, ("", "s")[n != 1])
>> 
>> The last newline is probably unnecessary. This seems be a bit more
>> readable:
>> print "I saw", n, "car" + ("", "s")[n != 1]
>> 
>> With Python 2.5 this looks better:
>> print "I saw", n, "car" + ("" if n == 1 else "s")
>> 
>> Or the vesion I like better:
>> print "I saw", n, ("car" if n == 1 else "cars")
>> 
>> Those () aren't necessary, but they help improve readability, and
>> avoid problems with operator precedence too. That if has a quite low
>> precedence.
>> 
>> Bye,
>> bearophile
>> 
> This is getting weird but here's 2 more in the spirit of
> "who needs the ternary operator - I don't!". And I'm starting to
> wonder what the 'obvious way' (as in 'Zen of Python') to write
> this would be.
> 
> print "I saw %d car%s" % (n, {1:''}.get(n==1, 's'))
> 
> print "I saw %d car%s" % (n, 's'*(n!=1))

Isn't that obvious? Don't do it in one line:

if n == 1:
print "I saw a car"
else:
print "I saw %d cars" % n

I guess that most of us will have read, understood, and verified (are there
any errors or cases that should be covered but aren't) those four lines
faster than any of the "smart" constructs, including the official 2.5
ternary operator. Now modify all proposed versions to print

I didn't see any cars
I saw 7 cars missing

for n=0 and n=-7, respectively, and you will see 1 light :-)

Peter

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


Re: strange test for None

2007-02-03 Thread Peter Otten
karoly.kiripolszky wrote:

> in my server i use the following piece of code:
> 
> ims = self.headers["if-modified-since"]
> if ims != None:
> t = int(ims)
> 
> and i'm always getting the following error:
> 
> t = int(ims)
> ValueError: invalid literal for int(): None
> 
> i wanna know what the hell is going on... first i tried to test using
> is not None, but it makes no difference.
> 
> sorry i forgot, it's interpreter 2.4.4.

Instead of the None singleton...

>>> int(None)
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: int() argument must be a string or a number

...you seem to have the /string/ "None" in your dictionary

>>> int("None")
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: invalid literal for int(): None

While the immediate fix would be

if ims != "None":
t = int(ims)

there is probably an erroneous

self.header["if-modified-since"] = str(value)

elsewhere in your code that you should replace with

if value is not None:
self.header["if-modified-since"] = str(value)

The quoted portion would then become

if "if-modified-since" in self.header:
t = int(self.headers["if-modified-since"])

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


Re: Regd. Regular expressions PyQt

2007-02-03 Thread David Boddie
On Saturday 03 February 2007 09:52, Paddy wrote:

> On Feb 3, 8:24 am, [EMAIL PROTECTED] wrote:

>> I am trying to work out a regular expression in a PyQt environment for
>> time in hh:mm:ss format. Any suggestions?
> 
> Yep,
> Use Kodos!
> http://kodos.sourceforge.net/
> 
> - It's Fab.

There's also a Python port of the Regular Expressions example from Qt
in the PyQt source distribution, though it's not as feature complete
as Kodos, obviously. :-)

Vishal should probably start by trying one of these tools, typing
something like

  (\d\d):(\d\d):(\d\d)

into the regular expression (or pattern) field.

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


Re: Python does not play well with others

2007-02-03 Thread Szabolcs Nagy

Paul Rubin wrote:
> "George Sakkis" <[EMAIL PROTECTED]> writes:
> > > What does "batteries included" mean to you?  To me, it means you don't
> > > have to install add-ons.
> >
> > So let's make a 500MB executable and add Numpy, Zope, Django, PIL,
> > pretty much everything actually. Even better, make CheeseShop just a
> > frontend to a build system that adds and updates automatically
> > submitted packages to the core. Problem solved ! .
>
> Numpy should certainly be included and I think there are efforts in
> that direction.  There is also a movement to choose a web framework to
> include and Django might be a good choice.  I think the Zope
> maintainers want to keep Zope separate and I think PIL has an
> incompatible license...

do not do that

(1)
i love when i can create a minimalistic system

think about it this way: what if you want to run python on an embeded/
low resource system?

if you want python to do webhosting the solution is _not_ to include
every related package

look at eg. debian: you can use it for lowresource system, desktop,
scientific computation and for webserver as well because of it's
package management system --> you can build a min. system and a huge
system as well.

(2)
seriously, python is a programming language and not a flee market (so
don't compare it to java or php)

unfortunately lots of ppl working on web related stuff think web is
the only reason a programming language should exist, which is pretty
stupid

i don't want a "webmodule" in a stdlib at all. implementing the
standards and recommendations should be enough. web in general is a
huge and ugly bloat, keep it away from a language core.

(3)
having a maintained set of modules for every possible problem is nice,
but shouldn't be a part of the core lib.

eg. numpy, mysql, ssl, pil, ... are not needed in the stdlib since
most of the programming tasks don't need those

they should be maintained separately, with an easy way to find and
install them. that's what cheese shop and distutils are for.

for me batteries included means i get a clean and consistent stdlib
and if i need special functionality i can add modules and extensions
easily

nsz

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


Re: strange test for None

2007-02-03 Thread rzed
"karoly.kiripolszky" <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> in my server i use the following piece of code:
> 
> ims = self.headers["if-modified-since"]
> if ims != None:
> t = int(ims)
> 
> and i'm always getting the following error:
> 
> t = int(ims)
> ValueError: invalid literal for int(): None
> 
> i wanna know what the hell is going on... first i tried to test
> using is not None, but it makes no difference.
> 

It appears that ims is the string 'None', so it fails the test, but 
is an invalid literal.

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


Re: urllib2 hangs "forever" where there is no network interface

2007-02-03 Thread John J. Lee
(I'm having news trouble, sorry if anybody sees a similar reply three
times...)

"dumbkiwi" <[EMAIL PROTECTED]> writes:
> On Feb 2, 5:02 am, [EMAIL PROTECTED] (John J. Lee) wrote:
> > "dumbkiwi" <[EMAIL PROTECTED]> writes:
[...]
> > > If there is no network interface, urllib2 hangs for a very long time
> > > before it raises an exception.  I have set the socket timeout with
> > > socket.setdefaulttimeout(), however, where there is no network
> > > interface, this seems to be ignored - presumably, because without a
> > > network interface, there is nothing for the socket module to interact
> > > with.
[...]
> > Presumably Windows?  (Unix systems almost always have at least a
> > loopback interface)
> >
> > John
> 
> Sorry, I should have been more specific.  The network interfaces are
> up - ie lo and eth1, it's where the wireless connection has dropped
> out.

The underlying problem is that Python's socket timeout is implemented
using select() or poll().  Those system calls only allow timing out
activity on file descriptors (e.g. sockets).  The problem you're
seeing is caused by getaddrinfo() blocking for a long time, and that
function doesn't involve file descriptors.  The problem should really
be fixed at the C level (in Modules/socketmodule.c), using something
like alarm() or a thread to apply a timeout to getaddrinfo() calls.


> Is the best solution to test for a wireless connection through /
> proc before trying to download data?

That may be a good practical solution.

Another workaround that might be useful is to do your DNS lookups only
once, then use only IP addresses.


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


Re: What is the Decisive "Clash" of Our Time?

2007-02-03 Thread Overlord
Another conspiracy theory nutterYou guys are so boring.

OL


<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Forget about the lunacy ... just enjoy these fun movies that are also
> on optics education. You can also save them by right clicking the
> links and saving them as flv files and download a free flv player.
> google is your friend.
>
> "Bush Administration Insider Says U.S. Government Behind 911.flv"
> "http://ash-v31.ash.youtube.com/get_video?video_id=HkpOsUmp-9w";
>
> "911 Truth, Scott Forbes describes power-downs in WTC.flv" "http://
> youtube-609.vo.llnwd.net/d1/04/D1/fEJmcvTzYfo.flv"
>
> "911 Truth, Consequences of Revealing the Truth about 911.flv" "http://
> youtube-609.vo.llnwd.net/d1/04/D1/fEJmcvTzYfo.flv"
>
> "U.S. Army General Says Flight 77 Did Not Hit Pentagon.flv"
> "http://lax-v8.lax.youtube.com/get_video?video_id=Zsn4JA450iA";
>
> "911 Truth, Bush Administration Lied About Iraq 911.flv" "http://lax-
> v8.lax.youtube.com/get_video?video_id=Zsn4JA450iA"
>
> "Bush gets caught off guard on 9/11 prior knowledge question.flv"
> "http://lax-v222.lax.youtube.com/get_video?video_id=0eH5qbrpwlM";
>
> "Bush gets caught off guard on 911 prior knowledge question.flv"
> "http://lax-v222.lax.youtube.com/get_video?video_id=0eH5qbrpwlM";
>
> "World Trade Center -- Controlled Demolition.flv" "http://
> v187.youtube.com/get_video?video_id=87fyJ-3o2ws"
>
> "911 Truth, The Moles, the Patsies, State-Sponsored Terror.flv"
> "http://chi-v43.chi.youtube.com/get_video?video_id=u0K9BM9oo90";
>
>
> On Jan 31, 7:56 pm, "Overlord" <[EMAIL PROTECTED]> wrote:
>> I never thought it would be possible for anyone to rival the lunacy of
>> Bitter Anko, but I was wrong...
>>
>> OL
>
> 


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


Re: newbie question: ftp.storbinary()

2007-02-03 Thread Ayaz Ahmed Khan
"Scott Ballard" typed:

> Sorry for the lame question, I'm still trying to pick up Python and new to 
> the list here.
> 
> Question:
> I'm trying to write a python script that will access an FTP site and upload 
> some files. I've gotten everything working except for the actual uploading 
> of the files.
> 
> I'm assuming that  I should use storbinary( command, file[, blocksize]) to 
> transfer the files. the documentation says "command should be an appropriate 
> "STOR" command: "STOR filename"."
> 
> I can't seem to figure out an `appropriate "STOR" command' is???

It frustrated the hell out of me too until I found this:

http://effbot.org/librarybook/ftplib.htm

The following works:

from ftplib import FTP
ftp = FTP()
ftp.set_debuglevel(2)
ftp.connect(_host, _port)
ftp.login(_user, _pass)
ftp.storbinary('STOR ' + _file, open(_file))
ftp.quit()

-- 
Ayaz Ahmed Khan

A witty saying proves nothing, but saying something pointless gets
people's attention.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can a jet fuel/hydrocarbon fire collapse a steel structure? An experiment.

2007-02-03 Thread stj911
On Feb 3, 1:08 am, "John Barrett" <[EMAIL PROTECTED]> wrote:
> <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
>
>
> > On Feb 2, 10:32 pm, "John Barrett" <[EMAIL PROTECTED]> wrote:
> >> <[EMAIL PROTECTED]> wrote in message
>
> >> >> > [snip]
> >> >> > Run your "experiment" again but  add some pure oxygen such as was
> >> >> > escaping from the on-board breathing oxygen tanks on the
> >> >> > airplanes that were crashed into the WTC.
>
> >> > No need to do it. We have the pictures of live humans waving from the
> >> > gaping holes in the towers where the planes crashed. We have the
> >> > testimonies of the fire fighters that the fires were not that hot and
> >> > minor. The fuel of the plane which is mainly in the wings were severed
> >> > outside the netting and much of them burnt outside in the fireball
> >> > that is visible in all the videos. Futhermore, the black soot that was
> >> > visible to the naked eye is indicative of bloody cold flame. Also, the
> >> > probability of the oxygen tanks oriented in such a way to inject
> >> > oxygen onto the steel as in a oxygen cutting torch is extremely low.
> >> > These cylinders have a 1000-3000psi of pressure which makes them into
> >> > a rocket or an explosive under uncontrolled gas release. And they
> >> > would not contaminate the molten metal with any sulfur. Either the
> >> > atmosphere inside was oxidising or reducing. If it was oxidising, how
> >> > did the sulfur in huge quantities contaminate the molten metal pools?
> >> > The official lies to explain sulfur is from the plaster wall. But that
> >> > requires a reducing atmosphere with finely divided and intimately
> >> > mixed reactants in a calciner where they are continuously rotated and
> >> > run for several hours. Yet the fires ran not even for an hour before
> >> > the building collapsed.
>
> >> OK - given all that -- you are left with only one conclusion (or at least
> >> I
> >> am) -- progressive structural failure, the loss of support where the
> >> plane
> >> hit was sufficient to put excessive stress on the remaining structural
> >> members, resulting in a catastrophic sequential failure
>
> > I dont think you have seen any actual structural failures, esp
> > progressive.
> > That happens often in earthquake and they have stacked floors. There
> > is
> > famous picture of an earthquake on these websites and in the videos.
> > Futhermore
> > due to erratic stops and goes in the progressive failure, the
> > structure falls on the side esp a big bldg like WTC1&2 should have
> > fallen from the tipping torque to one side. That did not happen. only
> > controlled demolition bldgs fall down straight.
>
> >> -- it doesnt take
> >> exotic chemical mixes to put excessive mechanical stress on a system...
> >> just
> >> chop out enough supports.. it may take time for the remaining supports to
> >> deform enough to reach the failure point.. but they will get there, as
> >> demonstrated -- occams razor dude -- the least hypothesis is usually the
> >> right one -- and I get enough conspiracy theory crap out of my dad --
> >> makes
> >> a good movie -- but doesnt pan out in real life -- too many
> >> whistle-blowers
> >> around !!
>
> > Occams razor is applicable to nature's works. human works are not
> > amenable to it. Besides, the official fairy tale is the conspiracy
> > theory.
>
> >> The city I live in is installing those red-light cameras to catch
> >> light-runners -- my dad likes to claim that they manipulate the yellow
> >> time
> >> to catch people in the intersection and increase revenue from traffic
> >> tickets -- I told him to shut up until he got out there with a stop watch
> >> and proved it -- and I say the same to you -- PROVE it -- then make some
> >> noise -- conjecture and conspiracy theories without proof are a waste of
> >> everyones time. -- how do you know the sulphur was in large quantities ??
> >> did you do a chemical analysis ?? or can you produce one done by a
> >> reputable
> >> metalurgy company ??
>
> > These pillars are not machinable steel. the sulfur here was excessive.
> > we are talking about intergranular corrosion, not that teeny amount
> > used for imparting machinability and that is not nowadays needed. It
> > only for cheap and rough chinese type crap and i am not sure even
> > there if someone would ruin their steel mills by adding this kind of
> > corrosive sulfur shit. come on dude ... dont mix categories.
>
> >> Ohhh and by the way -- high sulphur steels are regularly used for
> >> machined
> >> components -- was the amount of sulphur detected incosistent with what
> >> may
> >> have been present due to the use of high sulphur steels ?? (where is that
> >> metalurgy report again ??)
>
> > yeah a damn fool would put sulfur in the bolts and load bearing
> > elements such as the bolts of aircrafts and space shuttle.
>
> > Besides how do you explain the completely pulverized building ??
> > if not for explosives.
>
> lets try that again 

Re: compound statement from C "?:"

2007-02-03 Thread Jussi Salmela
Peter Otten kirjoitti:
> Isn't that obvious? Don't do it in one line:
> 
> if n == 1:
> print "I saw a car"
> else:
> print "I saw %d cars" % n
> 
> I guess that most of us will have read, understood, and verified (are there
> any errors or cases that should be covered but aren't) those four lines
> faster than any of the "smart" constructs, including the official 2.5
> ternary operator. Now modify all proposed versions to print
> 
> I didn't see any cars
> I saw 7 cars missing
> 
> for n=0 and n=-7, respectively, and you will see 1 light :-)
> 
> Peter
> 

It's naturally clear that a combination of if-elifs-else is more 
adaptable to different situations, but the OP's question was:

I would like to do the equivalent if python of the C line:
printf("I saw %d car%s\n", n, n != 1 ? "s" : "")

In this question I thought I recognized the familiar
tool=hammer==>problem:nail pattern of thought and tried to show
that in addition to the ternary operator Python has other ways of 
resolving that particular problem of his.

I'm certainly not an advocate of one-liners because at their extreme
they easily result in write-only solutions.

Cheers,
Jussi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the Decisive "Clash" of Our Time?

2007-02-03 Thread stj911
On Feb 3, 7:09 am, "Overlord" <[EMAIL PROTECTED]> wrote:
> Another conspiracy theory nutterYou guys are so boring.
>
> OL
>
> <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > Forget about the lunacy ... just enjoy these fun movies that are also
> > on optics education. You can also save them by right clicking the
> > links and saving them as flv files and download a free flv player.
> > google is your friend.
>
> > "Bush Administration Insider Says U.S. Government Behind 911.flv"
> > "http://ash-v31.ash.youtube.com/get_video?video_id=HkpOsUmp-9w";
>
> > "911 Truth, Scott Forbes describes power-downs in WTC.flv" "http://
> > youtube-609.vo.llnwd.net/d1/04/D1/fEJmcvTzYfo.flv"
>
> > "911 Truth, Consequences of Revealing the Truth about 911.flv" "http://
> > youtube-609.vo.llnwd.net/d1/04/D1/fEJmcvTzYfo.flv"
>
> > "U.S. Army General Says Flight 77 Did Not Hit Pentagon.flv"
> > "http://lax-v8.lax.youtube.com/get_video?video_id=Zsn4JA450iA";
>
> > "911 Truth, Bush Administration Lied About Iraq 911.flv" "http://lax-
> > v8.lax.youtube.com/get_video?video_id=Zsn4JA450iA"
>
> > "Bush gets caught off guard on 9/11 prior knowledge question.flv"
> > "http://lax-v222.lax.youtube.com/get_video?video_id=0eH5qbrpwlM";
>
> > "Bush gets caught off guard on 911 prior knowledge question.flv"
> > "http://lax-v222.lax.youtube.com/get_video?video_id=0eH5qbrpwlM";
>
> > "World Trade Center -- Controlled Demolition.flv" "http://
> > v187.youtube.com/get_video?video_id=87fyJ-3o2ws"
>
> > "911 Truth, The Moles, the Patsies, State-Sponsored Terror.flv"
> > "http://chi-v43.chi.youtube.com/get_video?video_id=u0K9BM9oo90";
>
> > On Jan 31, 7:56 pm, "Overlord" <[EMAIL PROTECTED]> wrote:
> >> I never thought it would be possible for anyone to rival the lunacy of
> >> Bitter Anko, but I was wrong...
>
> >> OL

LOL, thanks for the free service

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


How can I access data from MS Access?

2007-02-03 Thread Finger . Octopus
How to access data from MS Access? I tried ADOdb for Python but it
doesn't seems to work.

Even the official examples dont work, like this one:

import adodb
conn = adodb.NewADOConnection('access') # mxodbc required
dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\inetpub\\adodb\
\northwind.mdb;"
conn.Connect(dsn)


(I have downloaded mxodbc, but still it doesn't works)

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


Re: compound statement from C "?:"

2007-02-03 Thread Peter Otten
Jussi Salmela wrote:

> It's naturally clear that a combination of if-elifs-else is more
> adaptable to different situations, but the OP's question was:
> 
> I would like to do the equivalent if python of the C line:
> printf("I saw %d car%s\n", n, n != 1 ? "s" : "")

And my answer, triggered by your intermission

> And I'm starting to wonder what the 'obvious way' (as in 'Zen of Python')
> to write this would be.

was that in Python you would achieve the best results with if ... else
instead:

>> if n == 1:
>> print "I saw a car"
>> else:
>> print "I saw %d cars" % n

> In this question I thought I recognized the familiar
> tool=hammer==>problem:nail pattern of thought and tried to show
> that in addition to the ternary operator Python has other ways of
> resolving that particular problem of his.

It seems we operated on different levels of abstraction,

You: hammer=ternary operator
Me: hammer=oneliner
 
> I'm certainly not an advocate of one-liners because at their extreme
> they easily result in write-only solutions.

D'accord. Did I mention that, as a "for fun" approach, "s" * (n != 1) is
quite clever :-)

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


Re: Python does not play well with others

2007-02-03 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes:
> > Since Python is being touted as good for web apps as a competitor to
> > PHP
> 
> Python is being touted as a good language for *many* purposes, not
> just web applications. Python is also a "competitor" to Java, to Ruby,
> to Perl, to many other languages. They all have strengths and
> weaknesses.

Yes but in the cases where Python's weakness compared with one of
those other languages is lack of library functionality, if Python can
remedy the weakness by incorporating similar functionality into its
library it should do so.

> That doesn't follow at all. Many consider the humungous function
> library of PHP to be a significant downside of the system, which
> criterion leaves Python ahead. More is not necessarily better.

I've never heard that as a PHP criticism, at least in any large scale
deployment, which is what a hosting service is.

> > I'm paying the hosting company for access to a computer that's
> > connected to electricity and to the internet and which has a
> > straightforward OS, language package, web server, and db installed.
> 
> In which case, there should be no problem with *you* installing
> whatever software you need to use the system for what you want.

No.  That would be colo or something similar , where I'm basically
paying for bare metal plus electricity and network, and I'm completely
in charge of the software.  Web hosting means the ISP is in charge of
all the software except for my application (i.e. they handle the OS,
language package, web server, and db, as described above).  So they
run (typically) Linux, MySQL, Apache, and PHP; and I get to upload my
own PHP apps and use the PHP library.  That's a lot less work for me
since I don't have to stay on top of kernel patches or firewall
configuration, and it's cheaper because they host a bazillion sites
(virtual hosts) in a a single server instance.

> > They shouldn't have to deal with dozens of interdependent modules
> > downloaded from different places just to support one language.
> 
> Either they are providing far more than the minimal set you describe
> above, or this is entirely outside their domain. Make up your mind.

No it's you who's got it wrong, I just described above what they're
doing.  Do you actually use any services like this?

> You can't claim both that the hosting company should have to maintain
> a comprehensive set of functionality, *and* that they should not have to.

They should get a distro that includes a lot of stuff, type "make",
and all the stuff becomes available to their users.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Paul Rubin
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> This is simply not true. J2SE doesn't include a web-framework. J2EE
> does, but it's a separate multi-megabyte-download.

I thought J2SE comes with JSP.  Maybe that's not a "framework" in the
fancy sense though.

> PHP _is_ a web centered language, so to say it "includes" a

> And _both_ of them don't contain DB connectivity modules! J2SE has
> JDBC - which is just a bunch of interfaces. You need to download each
> and every driver. 

Hmm, I thought it came with drivers.  Maybe those come with the db
instead?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> I can't speak authoritatively for either PHP or J2SE, but I suspect the
> latter at least has some signifiant monetary support (if not outright gobs
> of human resources) from Sun.  PHP seems to have a more limited application
> domain (web apps) from which it has expanded a bit.  Can I build a PHP site
> out of the box with a PostgreSQL or Oracle backend? 

I believe so, from having looked at the docs a while back, but I
haven't tried it.

> Does J2SE have something comparable to Numpy or scipy?

I don't think so, but Python doesn't either.

> While might do the occasional bit of Python hacking for free, I still need
> to put food on the table.  My employer doesn't care if MySQLdb (to use one
> of your examples) is delivered with Python or not.  They aren't likely to
> want to support me to solve your problems.

The same could be said of Tkinter (a large and complex library module)
or IDLE (a full blown mid-sized application shipped with Python).  The
answer is the same for both: if you don't need to use a given module,
then don't.  Why would I expect your employer to solve my problems
anyway, even if they relate to some module that you actually use?
-- 
http://mail.python.org/mailman/listinfo/python-list


CTypes

2007-02-03 Thread [EMAIL PROTECTED]
I'm trying to install PyWinAuto for Python 2.4. It said that one of
the required libraries that I need to install would be CTypes. So I
head over to CTypes's SourceForge page and I installed CTypes for
Python 2.4. I go to run the PyWinAuto installation file and it throws
up this error:

C:\WINDOWS\Desktop\pywinauto-0.3.6>C:\Python24\Python setup.py install
Traceback (most recent call last):
  File "setup.py", line 29, in ?
import pywinauto
  File "C:\WINDOWS\Desktop\pywinauto-0.3.6\pywinauto\__init__.py",
line 28, in ?

import findwindows
  File "C:\WINDOWS\Desktop\pywinauto-0.3.6\pywinauto\findwindows.py",
line 31, i
n ?
import win32functions
  File "C:\WINDOWS\Desktop\pywinauto-0.3.6\pywinauto
\win32functions.py", line 14
9, in ?
GetModuleFileNameEx =
ctypes.windll.psapi.GetModuleFileNameExW

  File "C:\PYTHON24\lib\site-packages\ctypes\__init__.py", line 387,
in __getatt
r__
dll = self._dlltype(name)
  File "C:\PYTHON24\lib\site-packages\ctypes\__init__.py", line 312,
in __init__

self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 1157] One of the library files needed to run this
applicati
on cannot be found

I have found out that anything that calls CTypes is producing this
error. I looked into the CTypes source and I found:

def __init__(self, name, mode=DEFAULT_MODE, handle=None):
self._name = name
if handle is None:
self._handle = _dlopen(self._name, mode) http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> iceberg.)  The Pylons, web.py, Karrigell, Webware and TurboGears people
> might (rightly) feel slighted if you include Django but not their
> frameworks.

Yeah well, the Wxpython, PyQt, PyGTK etc. people may feel slighted
that Tkinter got included and their stuff didn't, and the Eric,
Eclipse, Komodo etc. people may feel slighted that IDLE got included,
but that doesn't stop Tkinter and IDLE from being useful and worth
shipping in Python.  We were talking about db connectivity modules
which are quite a bit simpler than tkinter.  We were also talking
about an SSL wrapper, which *is* included with Python, but is broken
(doesn't examine certificates) so people use external modules instead,
which is just lame.

> Where would you stop?  At the boundaries of your particular application
> interests?

Basic competitive analysis.  People ask here all the time "I'm trying
to write application XYZ, should I use language L or should I use
Python" (L is usually Java or PHP but can be other things).  There's
always immediately a flood of responses about why Python is better
than language L for application XYZ.  If the Pythonistas are serious
about such a claim, competitive analysis says they should be willing
to look at what language L does to support application XYZ (example:
PHP includes database connectivity), make a checklist of L's features,
and see to it that Python achieves (at least) parity in those areas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Message ("Your message dated Sat, 3 Feb 2007 10:40:10 -0500...")

2007-02-03 Thread SLACK Incorporated LISTSERV Server (14.3)
Your message dated Sat, 3 Feb 2007 10:40:10 -0500 with no subject has been
submitted to the moderator of the IDN-L list: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Jython

2007-02-03 Thread Boris Ozegovic
Hi

Why this doesn't work:

def go():
for line in open("bobo.txt", "r"):
print line

go()

python FileReader.py: everything ok
jython FileReader.py:

Traceback (innermost last):
  File "FileReader.py", line 6
  File "FileReader.py", line 3
AttributeError: __getitem__

-- 
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython

2007-02-03 Thread gregturn
On Feb 3, 11:21 am, Boris Ozegovic <[EMAIL PROTECTED]>
wrote:
> Hi
>
> Why this doesn't work:
>
> def go():
> for line in open("bobo.txt", "r"):
> print line
>
> go()
>
> python FileReader.py: everything ok
> jython FileReader.py:
>
> Traceback (innermost last):
>   File "FileReader.py", line 6
>   File "FileReader.py", line 3
> AttributeError: __getitem__
>
> --
> "A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
> silovana"

Files aren't lists and thus don't have the functions for iteration.

Try:

def go():
for line in open("bobo.txt", "r").readlines():
print line

go()

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


Re: Jython

2007-02-03 Thread Boris Ozegovic
[EMAIL PROTECTED] wrote:

> Files aren't lists and thus don't have the functions for iteration.

They do have iterator:

C:\Documents and Settings\Silovana Vjeverica\Desktop>python FileReader.py
'import site' failed; use -v for traceback
boris ozegovic
vedran ozegovic

-- 
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython

2007-02-03 Thread Boris Ozegovic
Boris Ozegovic wrote:

> [EMAIL PROTECTED] wrote:
> 
>> Files aren't lists and thus don't have the functions for iteration.
> 
> They do have iterator:
> 
> C:\Documents and Settings\Silovana Vjeverica\Desktop>python FileReader.py
> 'import site' failed; use -v for traceback
> boris ozegovic
> vedran ozegovic

But apparently not in Jython...  Only Python.

Tnx, anyway

-- 
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Kirk Sluder
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

> I do think the core should have more stuff than it does, so that its
> functionality can be on a par with competing language distros like
> J2SE and PHP.  Both of those distros include database connectvity
> modules and web frameworks.  

Can't speak for PHP, but J2SE requires the additional installation 
of the Mysql Connector/J JDBC driver.  Java also does not include a 
web framework as far as I can tell, with many people bolting on 
struts and Tomcat for this purpose.

Now granted, it may or may not be a good idea for python to copy the 
java way of doing things by including the generic database API into 
the core libraries rather than expect database module developers to 
use the API.  But that doesn't solve the core problem that you can't 
get database connectivity just through the core language.

And for that matter, perl doesn't include the database drivers or a 
web framework either.  

php does, but I've always considered php to be a web framework with 
an embedded programming language.   Comparing python to php here 
strikes me as comparing apples and oranges.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from __future__ import absolute_import ?

2007-02-03 Thread Ron Adam
Peter Otten wrote:
> Ron Adam wrote:
>
>>
>> work
>>   |
>>   |- foo.py# print "foo not in bar"
>>   |
>>   `- bar
>>   |
>>   |- __init__.py
>>   |
>>   |- foo.py# print "foo in bar"
>>   |
>>   |- absolute.py   # from __futer__ import absolute_import
>>   |# import foo
>>   |
>>   `- relative.py   # import foo
>>
>>
>> * Where "work" is in the path.
>>
>>
>> (1)
>>
>> C:\work>python -c "import bar.absolute"
>> foo not in bar
>>
>> C:\work>python -c "import bar.relative"
>> foo in bar
>>
>>
>> (2)
>>
>> C:\work>python -m "bar.absolute"
>> foo not in bar
>>
>> C:\work>python -m "bar.relative"
>> foo not in bar
>>
>>
>> (3)
>>
>> C:\work>python
>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
>> on win 32
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> import bar.absolute
>> foo not in bar
>>  >>> import bar.relative
>> foo in bar
>>
>>
>> (4)
>>
>> C:\work>cd bar
> 
> A path below the package level is generally a good means to shoot yourself
> in the foot and should be avoided with or without absolute import.

Seems so.  :-/


>> C:\work\bar>python -c "import bar.absolute"
>> foo in bar
>>
>> C:\work\bar>python -c "import bar.relative"
>> foo in bar
>>
>>
>> (5)
>>
>> C:\work\bar>python
>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
>> on win 32
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> import bar.absolute
>> foo in bar
>>  >>> import bar.relative
>> foo in bar
>>  >>>
>>
>>
>>
>> Case (2) seems like it is a bug.
> 
> I think so, too.

This one is the reasons I had trouble figuring it out.  I was using the -m 
command option when I tried to test it.

There is a bug report on absolute/relative imports already.  I'm not sure if 
this particular item is covered under it or not.  Doesn't sound like it as the 
bug report address the relative aspects of it.


>> Why not also have (4), and (5) do the same as cases (1) and (3)?
> 
> The work/bar directory is the current working directory and occurs in the
> path before the work directory. 

Yes. Unfortunately this is a side effect of using the os's directory structure 
to represent a python "package" structure.  If a package was represented as a 
combined single file.  Then the working directory would always be the package 
directory.


 > When bar.absolute imports foo python is
 > unaware that work/bar/foo.py is part of the bar package.

Umm isn't the "bar" stuck on the front of "bar.absolute" a pretty obvious 
hint.  ;-)

If you run the module directly as a file...

 python bar/foo.py
or  python foo.py

Then I can see that it doesn't know.  But even then, it's possible to find out. 
  ie... just check for an __init__.py file.

Python has a certain minimalist quality where it tries to do a lot with a 
minimum amount of resources, which I generally love.  But in this situation 
that 
might not be the best thing.  It would not be difficult for python to detect if 
a module is in a package, and determine the package location.  With the move to 
explicit absolute/relative imports, it would make since if python also were a 
little smarter in this area.


>> in cases (4) and (5), that is the result I would expect if I did:
>>
>> import absolute   # with no 'bar.' prefix.
>> import relative
>>
>>
>>  From what I understand, in 2.6 relative imports will be depreciated, and
>>  in 2.7
>> they will raise an error.  (providing plans don't change)
>>
>> Would that mean the absolute imports in (4) and (5) would either find the
>> 'foo not in bar' or raise an error?
> 
> No, in 1, 3 -- and 2 if the current behaviour is indeed a bug. This is only
> for the relative import which would have to be spelt
> 
> from . import foo

Was that a 'yes' for exampels 4 and 5, since 1,2 and 3 are 'no'?


> in an absolute-import-as-default environment;
> 
> import foo
> 
> would always be an absolute import.

But what is the precise meaning of "absolute import" in this un-dotted case?

Currently it is:

 "A module or package that is located in sys.path or the current directory".

But maybe a narrower interpretation may be better?:

 "A module or package found in sys.path, or the current directory
  and is *not* in a package."

If it's in a package then the dotted "absolute" name should be used. Right?


I guess what I'm getting at, is it would be nice if the following were always 
true.

 from __import__ import absolute_import


 import thispackage.module
 import thispackage.subpackage

   # If thispackage is the same name as the current package,
   # then do not look on sys.path.


 import otherpackage.module
 import otherpackage.subpackage

   # If otherpackage is a different name from the current package,
   # then do not look in this package.


 import module
 import package

   # Module and package are not in 

Re: Jython

2007-02-03 Thread Boris Ozegovic
[EMAIL PROTECTED] wrote:

> Files aren't lists and thus don't have the functions for iteration.
> 
> Try:
> 
> def go():
> for line in open("bobo.txt", "r").readlines():
> print line
> 
> go()

For example, you can do even this:

import sys

for line in sys.stdin:
print line, 


python FileReader.py < bobo.tx

'import site' failed; use -v for traceback
boris ozegovic
vedran ozegovic

-- 
"A mi smo stranci u vlastitoj zemlji zbog ljudskog sljama, lipa nasa
silovana"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP NEEDED ... Regd. Regular expressions PyQt

2007-02-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, vishal wrote:

> I am trying to work out a regular expression in a PyQt environment for
> time in hh:mm:ss format. Any suggestions?

Maybe don't use a re for something that simple.  Splitting at ``:``
characters, converting to `int` and checking the value ranges isn't that
hard without a regular expression.

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


Re: Jython

2007-02-03 Thread Peter Otten
Boris Ozegovic wrote:

> Boris Ozegovic wrote:
> 
>> [EMAIL PROTECTED] wrote:
>> 
>>> Files aren't lists and thus don't have the functions for iteration.
>> 
>> They do have iterator:
>> 
>> C:\Documents and Settings\Silovana Vjeverica\Desktop>python FileReader.py
>> 'import site' failed; use -v for traceback
>> boris ozegovic
>> vedran ozegovic
> 
> But apparently not in Jython...  Only Python.

Iterable files were introduced in Python 2.2. Jython implements Python2.1,
it seems.

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


Re: LDAP/LDIF Parsing

2007-02-03 Thread Bruno Desthuilliers
Hallvard B Furuseth a écrit :
> Bruno Desthuilliers writes:
> 
>>Hallvard B Furuseth a écrit :
>>
 else:
   # all LDAP attribs are multivalued by default,
   # even when the schema says they are monovalued
   if len(data) == 1:
  return data[0]
   else:
  return data[:]
>>>
>>>IMHO, this just complicates the client code since the client needs to
>>>inserts checks of isinstance(return value, list) all over the place.
>>>Better to have a separate method which extracts just the first value of
>>>an attribute, if you want that.
>>
>>Most of the times, in a situation such as the one described by the OP,
>>one knows by advance if a given LDAP attribute will be used as
>>monovalued or multivalued. Well, this is at least my own experience...
>  
> But if the attribute is multivalued, you don't know if it will contain
> just one value or not.

If you know which attributes are supposed to be multivalued in your 
specific application, then it's time to write a more serious, 
application-specific wrapper.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can a jet fuel/hydrocarbon fire collapse a steel structure? An experiment.

2007-02-03 Thread Jonathan Curran
I've been seeing this topic for a day or two so far. Why don't we stick to 
discussing python on this mailing list? I'm sure there are other mailing 
lists specifically for discussing chemistry. =\

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


Re: Python does not play well with others

2007-02-03 Thread Diez B. Roggisch
Paul Rubin schrieb:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>> This is simply not true. J2SE doesn't include a web-framework. J2EE
>> does, but it's a separate multi-megabyte-download.
> 
> I thought J2SE comes with JSP.  Maybe that's not a "framework" in the
> fancy sense though.

JSP is also part of J2EE.

http://java.sun.com/products/jsp/

"""
Another key concern of the Java EE 5 specification has been the 
alignment of its webtier technologies, namely JavaServer Pages (JSP), 
JavaServer Faces (JSF), and JavaServer Pages Standard Tag Library (JSTL).
"""

>> PHP _is_ a web centered language, so to say it "includes" a
> 
>> And _both_ of them don't contain DB connectivity modules! J2SE has
>> JDBC - which is just a bunch of interfaces. You need to download each
>> and every driver. 
> 
> Hmm, I thought it came with drivers.  Maybe those come with the db
> instead?

Might be, for some. For others where the vendor doesn't care about Java, 
they aren't.

And they certainly require special treatment like putting them in the 
classpath, setting up the project directory and the like - no simple 
import will work out of the box, as it would witch python standard lib 
drivers.

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


Re: How can I access data from MS Access?

2007-02-03 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> How to access data from MS Access? I tried ADOdb for Python but it
> doesn't seems to work.
> 
> Even the official examples dont work, like this one:
> 
> import adodb
> conn = adodb.NewADOConnection('access') # mxodbc required
> dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\inetpub\\adodb\
> \northwind.mdb;"
> conn.Connect(dsn)
> 
> 
> (I have downloaded mxodbc, but still it doesn't works)
> 
"doesn't work" is the worst possible description of a problem. Did it 
print out some insults in a foreign language ? wipe out your HD ? Else ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Diez B. Roggisch
Paul Rubin schrieb:
> [EMAIL PROTECTED] writes:
>> I can't speak authoritatively for either PHP or J2SE, but I suspect the
>> latter at least has some signifiant monetary support (if not outright gobs
>> of human resources) from Sun.  PHP seems to have a more limited application
>> domain (web apps) from which it has expanded a bit.  Can I build a PHP site
>> out of the box with a PostgreSQL or Oracle backend? 
> 
> I believe so, from having looked at the docs a while back, but I
> haven't tried it.

The docs cover all the available drivers, as they are hard-coded in the 
source. Yet you need to specify inclusion of them at compile-time, and 
as I said: some distros don't ship with non-OS-drivers.

>> Does J2SE have something comparable to Numpy or scipy?
> 
> I don't think so, but Python doesn't either.
> 
>> While might do the occasional bit of Python hacking for free, I still need
>> to put food on the table.  My employer doesn't care if MySQLdb (to use one
>> of your examples) is delivered with Python or not.  They aren't likely to
>> want to support me to solve your problems.
> 
> The same could be said of Tkinter (a large and complex library module)
> or IDLE (a full blown mid-sized application shipped with Python).  The
> answer is the same for both: if you don't need to use a given module,
> then don't.  Why would I expect your employer to solve my problems
> anyway, even if they relate to some module that you actually use?

As far as I can tell, primary concerns for inclusion of modules are twofold:

  - dependencies, which certainly are an issue for DB-modules! Or do you 
want every python build to need the oracle OCI drivers installed? Plus 
headers?

  - maintainer commitment.

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


Re: Python does not play well with others

2007-02-03 Thread Kirk Sluder
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

> [EMAIL PROTECTED] writes:
> > Where would you stop?  At the boundaries of your particular application
> > interests?
> 
> If the Pythonistas are serious
> about such a claim, competitive analysis says they should be willing
> to look at what language L does to support application XYZ (example:
> PHP includes database connectivity), make a checklist of L's features,
> and see to it that Python achieves (at least) parity in those areas.

Well, digging into this, php includes database connectivity if 
compiled against the database client libraries.  So it's not as if 
you can just download php and have it work against the database you 
want.  

I also don't think that python as a general-purpose programming 
language is in direct competition to web frameworks like PHP and 
ColdFusion.  Perhaps the right answer is to say that PHP is a better 
solution for people wanting a web templating framework with embedded 
scripting, while Python is a better solution for people who want a 
general scripting/application language with broad support for 
specific applications via add-on modules. 

But then again, I'm one of those heterodox people who argue that one 
should fit the tool to the problem.  Common Lisp, bash, awk, sed and 
R are other great languages for different domains.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Paul Rubin
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> And they certainly require special treatment like putting them in the
> classpath, setting up the project directory and the like - no simple
> import will work out of the box, as it would witch python standard lib
> drivers.

Well, that's nowhere near as big a deal as having yet another set of
vendors or maintainer to deal with.  Minimizing configuration is nice,
but getting your software from as few different sources as possible is
also a big win.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I access data from MS Access?

2007-02-03 Thread Finger . Octopus
On Feb 3, 10:27 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] a écrit :> How to access data from MS Access? I tried ADOdb 
> for Python but it
> > doesn't seems to work.
>
> > Even the official examples dont work, like this one:
>
> > import adodb
> > conn = adodb.NewADOConnection('access') # mxodbc required
> > dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\inetpub\\adodb\
> > \northwind.mdb;"
> > conn.Connect(dsn)
>
> > (I have downloaded mxodbc, but still it doesn't works)
>
> "doesn't work" is the worst possible description of a problem. Did it
> print out some insults in a foreign language ? wipe out your HD ? Else ?

I havn't said "doesn't work", I rather doesn't seem to work.

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


Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-03 Thread John Nagle
Gabriel Genellina wrote:
> En Sat, 03 Feb 2007 06:12:33 -0300, Peter Otten <[EMAIL PROTECTED]>  
> escribió:
> 
>> John Nagle wrote:
>>
>>>How do I suppress "DeprecationWarning: Old style callback, use
>>>cb_func(ok,
>>> store) instead".  A library is triggering this message, the library is
>>> being fixed, but I need to make the message disappear from the 
>>> output  of a
>>> CGI program.
>>
>>
>> import warnings
>> warnings.filterwarnings("ignore", message="Old style callback, use
>> cb_func(ok, store) instead")

Thanks.

Actually, just copying the message into the string doesn't work; the
matching argument is a regular expression, so "(" has special meaning.
But the general idea is right.

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


Re: strange test for None

2007-02-03 Thread Michael Bentley

On Feb 3, 2007, at 7:47 AM, karoly.kiripolszky wrote:

> in my server i use the following piece of code:
>
> ims = self.headers["if-modified-since"]
> if ims != None:
> t = int(ims)
>
> and i'm always getting the following error:
>
> t = int(ims)
> ValueError: invalid literal for int(): None
>
> i wanna know what the hell is going on... first i tried to test using
> is not None, but it makes no difference.

Sounds like ims == 'None'.  Try changing:

if ims != None:

to

if ims:

and you might also wrap your call to int(ims) in a try block.

HTH,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I access data from MS Access?

2007-02-03 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> On Feb 3, 10:27 pm, Bruno Desthuilliers

>> "doesn't work" is the worst possible description of a problem. Did it
>> print out some insults in a foreign language ? wipe out your HD ? Else ?
 
> I havn't said "doesn't work", I rather doesn't seem to work.

Bruno, admit that you were wrong. Finger.Octopus is able to give a
description that is even worse than what you deemed possible :-)

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


PYTHONPATH or any other way to set seachpath (winXP) ?

2007-02-03 Thread Stef Mientki
Is it possible to change the searchpath for modules on the flight,
under winXP ?
Most preferred is some command to extend the searchpath.
(the environment variable PYTHONPATH needs a reboot)

thanks,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-02-03 Thread Jorge Godoy
Paul Rubin  writes:

> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>> And they certainly require special treatment like putting them in the
>> classpath, setting up the project directory and the like - no simple
>> import will work out of the box, as it would witch python standard lib
>> drivers.
>
> Well, that's nowhere near as big a deal as having yet another set of
> vendors or maintainer to deal with.  Minimizing configuration is nice,
> but getting your software from as few different sources as possible is
> also a big win.

So we should get a better egg support.  Then it would all be just a matter of
easy_install .  As it is that easy for thousands of modules on CPAN
for Perl. 

-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange test for None

2007-02-03 Thread karoly.kiripolszky
the tested variable was really a string containing "None" instead of
simply None. this is the first time i ran into this error message
confusion. :)

thanks for the help!

On Feb 3, 6:29 pm, Michael Bentley <[EMAIL PROTECTED]> wrote:
> On Feb 3, 2007, at 7:47 AM, karoly.kiripolszky wrote:
>
> > in my server i use the following piece of code:
>
> > ims = self.headers["if-modified-since"]
> > if ims != None:
> > t = int(ims)
>
> > and i'm always getting the following error:
>
> > t = int(ims)
> > ValueError: invalid literal for int(): None
>
> > i wanna know what the hell is going on... first i tried to test using
> > is not None, but it makes no difference.
>
> Sounds like ims == 'None'.  Try changing:
>
> if ims != None:
>
> to
>
> if ims:
>
> and you might also wrap your call to int(ims) in a try block.
>
> HTH,
> Michael


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


Re: Checking default arguments

2007-02-03 Thread George Sakkis
On Feb 2, 1:30 pm, [EMAIL PROTECTED] (Igor V. Rafienko) wrote:
> Hi,
>
> I was wondering whether it was possible to find out which parameter
> value is being used: the default argument or the user-supplied one.
> That is:
>
> def foo(x, y="bar"):
> # how to figure out whether the value of y is
> # the default argument, or user-supplied?
>
> foo(1, "bar") => user-supplied
> foo(1)=> default
>
> {}.pop seems to be able to make this dictinction.
>
> I've checked the inspect module, but nothing obvious jumped at me. Any
> hints?

I don't know why you might want to distinguish between the two in
practice (the unique object idea mentioned in other posts should
handle most uses cases), but if you insist, here's one way to do it:

import inspect

def determine_supplied_args(func):
varnames,_,_,defaults = inspect.getargspec(func)
num_varnames = len(varnames); num_defaults = len(defaults)
def wrapper(*args, **kwds):
max_defaults = min(num_defaults, num_varnames-len(args))
supplied_args = dict(zip(varnames,args))
default_args = {}
if max_defaults > 0:
for var,default in zip(varnames[-max_defaults:], defaults[-
max_defaults:]):
# if passed as keyword argument, don't use the default
if var in kwds:
supplied_args[var] = kwds[var]
else:
default_args[var] = default
wrapper._supplied_args = supplied_args
wrapper._default_args = default_args
return func(*args, **kwds)
return wrapper


@determine_supplied_args
def f(x, y='bar', z=None, *args, **kwds):
print "Supplied:", f._supplied_args
print "Default:", f._default_args


>>> f(1)
Supplied: {'x': 1}
Default: {'y': 'bar', 'z': None}
>>> f(1, 'bar')
Supplied: {'y': 'bar', 'x': 1}
Default: {'z': None}
>>> f(1, y='bar')
Supplied: {'y': 'bar', 'x': 1}
Default: {'z': None}
>>> f(1, z=None)
Supplied: {'x': 1, 'z': None}
Default: {'y': 'bar'}
>>> f(1, 'bar', None)
Supplied: {'y': 'bar', 'x': 1, 'z': None}
Default: {}
>>> f(1, 'bar', z=None)
Supplied: {'y': 'bar', 'x': 1, 'z': None}
Default: {}
>>> f(1, z=None, y='bar')
Supplied: {'y': 'bar', 'x': 1, 'z': None}
Default: {}


Regards,
George

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


Re: Jython

2007-02-03 Thread bearophileHUGS
[EMAIL PROTECTED]:
> Files aren't lists and thus don't have the functions for iteration.
> Try:
> def go():
> for line in open("bobo.txt", "r").readlines():
> print line
> go()

CPython 2.1 has xreadlines, maybe Jython has it too.

Bye,
bearophile

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


Re: Create a cookie with cookielib

2007-02-03 Thread Matthew Franz
I'm not sure what you mean be forge, but if you mean set an arbitrary
cookie manually (vs. one that was provided by the server).  just use
add_header() in http://docs.python.org/lib/request-objects.html

It may be possible to use CookieJar for this purpose but I've only
used it for manipulating cookies set by the server...

And  I would agree that Python cookie APIs are less intuitive than
what are available in others such as Jakarta HttpClient

- mdf

On 2/3/07, Alessandro Fachin <[EMAIL PROTECTED]> wrote:
> Hi, i am trying to forge a new cookie by own with cookielib. But i don't
> still have success. This a simply code:
>
> import cookielib, urllib, urllib2
> login = 'Ia am a cookie!'
> cookiejar = cookielib.CookieJar()
> urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
> values = {'user':login}
> data = urllib.urlencode(values)
> request = urllib2.Request("http://localhost/cookie.php";, data)
> url = urlOpener.open(request)
> print url.info()
> page = url.read(50)
> print page
> print cookiejar
>
> the output of this is:
>
> Date: Sat, 03 Feb 2007 10:20:05 GMT
> Server: Apache
> X-Powered-By: PHP/5.1.6
> Set-Cookie: user=Alex+Porter; expires=Sat, 03-Feb-2007 11:20:05 GMT
> Content-Length: 11
> Connection: close
> Content-Type: text/html; charset=UTF-8
>
> Array
> (
> )
> ]>
>
> And here is the code of cookie.php that i've create for this example:
>
>  setcookie("user", "Alex Porter", time()+3600);
> ?>
>  // Print a cookie
> echo $_COOKIE["user"];
> // A way to view all cookies
> print_r($_COOKIE);
> ?>
>
> if anyone could help... Thank you
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


confused about resizing array in Python

2007-02-03 Thread Ruan
My confusion comes from the following piece of code:

 memo = {1:1, 2:1}
def fib_memo(n):
global memo
if not n in memo:
memo[n] = fib_memo(n-1) + fib_memo(n-2)
return memo[n]

I used to think that the time complexity for this code is O(n) due to its
use of memoization.

However, I was told recently that in Python, dictionary is a special kind of
array and to append new element to it or to resize it, it is in fact
internally inplemented by creating another array and copying the old one to
it and append a new one.

Therefore, for "memo[n] = fib_memo(n-1) + fib_memo(n-2)", the time it taks
is not at all constant. The larger the n grows, the more time this statement
takes.

Can anybody here familiar with the internal mechanism of python confirm
this?


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


Re: nokia pys60 contacts + calendar

2007-02-03 Thread worlman385
On 3 Feb 2007 02:38:02 -0800, "cyberco" <[EMAIL PROTECTED]> wrote:

>You can most likely find an answer on Nokia's Python forum:
>http://discussion.forum.nokia.com/forum/forumdisplay.php?f=102
>
>And if there's no answer there you should post the question there :)

cyberco,

do you knwo the answer?

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


Decimating Excel files

2007-02-03 Thread gonzlobo
No, I don't want to destroy them (funny how the word 'decimate' has
changed definition over the years) :).

We have a data acquisition program that saves its output to Excel's
.xls format. Unfortunately, the programmer was too stupid to write
files the average user can read.

I'd like some advice on how to go about:
1. Reading a large Excel file and chop it into many Excel files (with
only 65535 lines per file)
or
2. Decimate an Excel file & write... say every other line (user
selectable)... to a new file.

I'm pretty experienced at reading and writing simple text files, but
this is my first foray into using COM. I would imagine either choice 1
or 2 is pretty simple once I can get the file open.

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


Determining encoding of a file

2007-02-03 Thread Tony Houghton
In Linux it's possible for filesystems to have a different encoding from
the system's setting. Given a filename, is there a (preferably) portable
way to determine its encoding?

-- 
TH * http://www.realh.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: confused about resizing array in Python

2007-02-03 Thread Roel Schroeven
Ruan schreef:
> My confusion comes from the following piece of code:
> 
>  memo = {1:1, 2:1}
> def fib_memo(n):
> global memo
> if not n in memo:
> memo[n] = fib_memo(n-1) + fib_memo(n-2)
> return memo[n]
> 
> I used to think that the time complexity for this code is O(n) due to its
> use of memoization.
> 
> However, I was told recently that in Python, dictionary is a special kind of
> array and to append new element to it or to resize it, it is in fact
> internally inplemented by creating another array and copying the old one to
> it and append a new one.

That's not correct. Python dictionaries are highly optimized and I 
believe the time complexity is amortized constant (i.e. O(1)) for both 
insertions and lookups.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: PYTHONPATH or any other way to set seachpath (winXP) ?

2007-02-03 Thread Sick Monkey

If you need to extend your PATH variable, I have used this in the past.

~~
def AddSysPath(new_path):
   new_path = os.path.abspath(new_path)
   do = -1
   if os.path.exists(new_path):
   do = 1
   # check against all paths currently available
   for x in sys.path:
   x = os.path.abspath(x)
   if sys.platform == 'win32':
   x = x.lower()
   if new_path in (x, x + os.sep):
   do = 0
   # add path if we don't already have it
   if do:
   sys.path.append(new_path)
   pass

   return do

On 2/3/07, Stef Mientki <[EMAIL PROTECTED]> wrote:


Is it possible to change the searchpath for modules on the flight,
under winXP ?
Most preferred is some command to extend the searchpath.
(the environment variable PYTHONPATH needs a reboot)

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list

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

SndObj-Pysonic-omde-MusicKit-Jack-Alsa

2007-02-03 Thread Silver Rock

Greetings,

I've been studiyng python and some things are not that clear:

1- Is python too slow to efectivelly communicate with Jack? PyJack did not
seem to work right, so i tried PySndObj's JackIO object. It did not behave
as good as with connection with ALSA.

(btw, I could not acess lots of objects in the SndObj library (like Ocil,
Rand, while acessing normally Oscilli and Randh...)  Does anyone know why?)

2- Python comes with the ossaudiodev module for communication with OSS; Alsa
is compatible so it works. Shuld one use this module or use the pyalsasound?


3- pySonic - pySonic the wrapper for the FMOD sound library. but it is not
opensource... is there a standard library for sound processing in projects
like ardour.

4- Are any differences between 'r' and 'rb'; 'w' and 'wb' in:

wave.open('file', 'r')wave.open('file', 'rb')
wave.open('file', 'w')   wave.open('file', 'wb')

??

5- I found pySonic, that seems good but it is not open. MusicKit and
PySndObj and omde. Ow yeah, and Pygame. Can anyone expose ihre personal
experience and explain why?

Please be nice,
Claire
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Determining encoding of a file

2007-02-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Tony Houghton wrote:

> In Linux it's possible for filesystems to have a different encoding from
> the system's setting. Given a filename, is there a (preferably) portable
> way to determine its encoding?

No.

Ciao,
Marc 'BlackJack' Rintsch

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


Re: asyncore DoS vulnerability

2007-02-03 Thread billie
On 2 Feb, 17:09, "Chris Mellon" <[EMAIL PROTECTED]> wrote:

> Thats like asking why you should have to move your fingers to type or
> why you should have to eat food in order to not starve. Windows is
> placing a limit of 512 descriptors per process. Call Microsoft if you
> want to go over that.

?
That's not a select() problem: that's an asyncore problem.
I'm just saying that asyncore should handle this event in some other
way than raising a not well defined "ValueError".
I've discovered this problem accidentally by writing a small test
script but personally I've never seen a paper describing it.
Not handling such a problem just means that an asyncore based server
is vulnerable to DoS attacks and I believe that a lot of servers out
there didn't used a try/except statement around "asyncore.loop()".
imho, such a problem should merit some attention.
Don't you agree?

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


wave

2007-02-03 Thread Silver Rock

hallo,

supose i´ve opened a sound with the wave module:


import wave
sound=wave.open(filename,'rb')


now this is strange:


sound.getnframes() != len(sound.readframes(sound.getnframes())

True

Why so?

thanks in advance,
Claire
-- 
http://mail.python.org/mailman/listinfo/python-list

ctypes.com.IUnknown

2007-02-03 Thread Robin Becker
I find that ctypes.com has disappeared from the ctypes extension bundled 
with Python 2.5. I think I only need the IUnknown, I was playing with 
building a dialog using venster, but it needs IUnknown, STDMETHOD, 
HRESULT, GUID from ctypes.com. Any ideas what should replace those or is 
venster now too old to bother with.
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >