Re: how can i use lxml with win32com?

2009-10-25 Thread elca

Hello,
yes there is some reason why i nave to insist internet explorere interface.
because of javascript im trying to insist use PAMIE.
i was tried some other solution urlopen or mechanize and so on.
but it hard to use javascript.
can you show me some sample for me ? :)
such like if i want to extract some text in CNN website with 'CNN Shop'
'Site map' in bottom of CNN website page by use PAMIE.
thanks for your help.



motoom wrote:
> 
> 
> On 25 Oct 2009, at 07:45 , elca wrote:
> 
>> i want to make web scraper.
>> if possible i really want to make it work together with  
>> beautifulsoup or
>> lxml with PAMIE.
> 
> Scraping information from webpages falls apart in two tasks:
> 
> 1. Getting the HTML data
> 2. Extracting information from the HTML data
> 
> It looks like you want to use Internet Explorer for getting the HTML  
> data; is there any reason you can't use a simpler approach like using  
> urllib2.urlopen()?
> 
> Once you have the HTML data, you could feed it into BeautifulSoup or  
> lxml.
> 
> Mixing up 1 and 2 into a single statement created some confusion for  
> you, I think.
> 
> Greetings,
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26045673.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: how can i use lxml with win32com?

2009-10-25 Thread User


On 25 Oct 2009, at 08:06 , elca wrote:


because of javascript im trying to insist use PAMIE.


I see, your problem is not with lxml or BeautifulSoup, but getting the  
raw data in the first place.




i want to extract some text in CNN website with 'CNN Shop'
'Site map' in bottom of CNN website page


What text? Can you give an example?  I'd like to be able to reproduce  
it manually in the webbrowser so I get a clear idea what exactly  
you're trying to achieve.


Greetings,

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


Re: how can i use lxml with win32com?

2009-10-25 Thread elca

hello,
www.cnn.com in main website page.
for example ,if you see www.cnn.com's html source, maybe you can find such
like line of html source.

http://www.turnerstoreonline.com/ CNN Shop 

and for example if i want to extract 'CNN Shop' text in html source.
and i want to add such like function ,with following script source.

from BeautifulSoup import BeautifulSoup
from PAM30 import PAMIE
from time import sleep

url = 'http://www.cnn.com'
ie = PAMIE(url)
sleep(10)
bs = BeautifulSoup(ie.getTextArea()) 
#from here i want to add such like text extract function with use PAMIE and
lxml or beautifulsoup.

thanks for your help .


in the cnn website's html source
there i

motoom wrote:
> 
> 
> On 25 Oct 2009, at 08:06 , elca wrote:
> 
>> because of javascript im trying to insist use PAMIE.
> 
> I see, your problem is not with lxml or BeautifulSoup, but getting the  
> raw data in the first place.
> 
> 
>> i want to extract some text in CNN website with 'CNN Shop'
>> 'Site map' in bottom of CNN website page
> 
> What text? Can you give an example?  I'd like to be able to reproduce  
> it manually in the webbrowser so I get a clear idea what exactly  
> you're trying to achieve.
> 
> Greetings,
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26045766.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: how can i use lxml with win32com?

2009-10-25 Thread User


On 25 Oct 2009, at 08:33 , elca wrote:


www.cnn.com in main website page.
for example ,if you see www.cnn.com's html source, maybe you can  
find such

like line of html source.
http://www.turnerstoreonline.com/ CNN Shop
and for example if i want to extract 'CNN Shop' text in html source.


So, if I understand you correctly, you want your program to do the  
following:


1. Retrieve the http://cnn.com webpage
2. Look for a link identified by the text "CNN Shop"
3. Extract the URL for that link.

The result would be http://www.turnerstoreonline.com

Is that what you want?

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


Re: how can i use lxml with win32com?

2009-10-25 Thread elca

hello,
im very sorry my english.
yes i want to extract this text 'CNN Shop' and linked page
'http://www.turnerstoreonline.com'.
thanks a lot!



motoom wrote:
> 
> 
> On 25 Oct 2009, at 08:33 , elca wrote:
> 
>> www.cnn.com in main website page.
>> for example ,if you see www.cnn.com's html source, maybe you can  
>> find such
>> like line of html source.
>> http://www.turnerstoreonline.com/ CNN Shop
>> and for example if i want to extract 'CNN Shop' text in html source.
> 
> So, if I understand you correctly, you want your program to do the  
> following:
> 
> 1. Retrieve the http://cnn.com webpage
> 2. Look for a link identified by the text "CNN Shop"
> 3. Extract the URL for that link.
> 
> The result would be http://www.turnerstoreonline.com
> 
> Is that what you want?
> 
> Greetings,
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26045811.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


yes i want to extract this text 'CNN Shop' and linked page
'http://www.turnerstoreonline.com'.


Well then.
First, we'll get the page using urrlib2:

doc=urllib2.urlopen("http://www.cnn.com";)

Then we'll feed it into the HTML parser:

soup=BeautifulSoup(doc)

Next, we'll look at all the links in the page:

for a in soup.findAll("a"):

and when a link has the text 'CNN Shop', we have a hit,
and print the URL:

if a.renderContents()=="CNN Shop":
print a["href"]


The complete program is thus:

import urllib2
from BeautifulSoup import BeautifulSoup

doc=urllib2.urlopen("http://www.cnn.com";)
soup=BeautifulSoup(doc)
for a in soup.findAll("a"):
if a.renderContents()=="CNN Shop":
print a["href"]


The example above can be condensed because BeautifulSoup's find function 
can also look for texts:


print soup.find("a",text="CNN Shop")

and since that's a navigable string, we can ascend to its parent and 
display the href attribute:


print soup.find("a",text="CNN Shop").findParent()["href"]

So eventually the whole program could be collapsed into one line:

print 
BeautifulSoup(urllib2.urlopen("http://www.cnn.com";)).find("a",text="CNN 
Shop").findParent()["href"]


...but I think this is very ugly!


> im very sorry my english.

You English is quite understandable.  The hard part is figuring out what 
exactly you wanted to achieve ;-)


I have a question too.  Why did you think JavaScript was necessary to 
arrive at this result?


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


Re: how can i use lxml with win32com?

2009-10-25 Thread Stefan Behnel
elca, 25.10.2009 08:46:
> im very sorry my english.

It's fairly common in this news-group that people do not have a good level
of English, so that's perfectly ok. But you should try to provide more
information in your posts. Be explicit about what you tried and what failed
(and how!), and provide short code examples and exact copies of failure
messages whenever possible. That will help others in understanding what is
going on on your side. Remember that we can't look at your screen, nor read
your mind.

Oh, and please don't top-post in replies.

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


Re: how can i use lxml with win32com?

2009-10-25 Thread elca

Hello,
thanks for your reply.
actually what i want to parse website is some different language site.
so i was quote some common english website for easy understand.   :)
by the way, is it possible to use with PAMIE and beautifulsoup work
together?
Thanks a lot



motoom wrote:
> 
> elca wrote:
> 
>> yes i want to extract this text 'CNN Shop' and linked page
>> 'http://www.turnerstoreonline.com'.
> 
> Well then.
> First, we'll get the page using urrlib2:
> 
>  doc=urllib2.urlopen("http://www.cnn.com";)
> 
> Then we'll feed it into the HTML parser:
> 
>  soup=BeautifulSoup(doc)
> 
> Next, we'll look at all the links in the page:
> 
>  for a in soup.findAll("a"):
> 
> and when a link has the text 'CNN Shop', we have a hit,
> and print the URL:
> 
>  if a.renderContents()=="CNN Shop":
>  print a["href"]
> 
> 
> The complete program is thus:
> 
> import urllib2
> from BeautifulSoup import BeautifulSoup
> 
> doc=urllib2.urlopen("http://www.cnn.com";)
> soup=BeautifulSoup(doc)
> for a in soup.findAll("a"):
>  if a.renderContents()=="CNN Shop":
>  print a["href"]
> 
> 
> The example above can be condensed because BeautifulSoup's find function 
> can also look for texts:
> 
>  print soup.find("a",text="CNN Shop")
> 
> and since that's a navigable string, we can ascend to its parent and 
> display the href attribute:
> 
>  print soup.find("a",text="CNN Shop").findParent()["href"]
> 
> So eventually the whole program could be collapsed into one line:
> 
>  print 
> BeautifulSoup(urllib2.urlopen("http://www.cnn.com";)).find("a",text="CNN 
> Shop").findParent()["href"]
> 
> ...but I think this is very ugly!
> 
> 
>  > im very sorry my english.
> 
> You English is quite understandable.  The hard part is figuring out what 
> exactly you wanted to achieve ;-)
> 
> I have a question too.  Why did you think JavaScript was necessary to 
> arrive at this result?
> 
> Greetings,
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26045979.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


actually what i want to parse website is some different language site.


A different website?  What website?  What text?  Please show your actual 
use case, instead of smokescreens.




so i was quote some common english website for easy understand.   :)


And, did you learn something from it?  Were you able to apply the 
technique to the other website?




by the way, is it possible to use with PAMIE and beautifulsoup work
together?


If you define 'working together' as like 'PAMIE produces a HTML text and 
BeautifulSoup parses it', then maybe yes.


Greetings,

--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Socket logic problem

2009-10-25 Thread Gabriel Genellina
En Sat, 24 Oct 2009 06:40:08 -0300, John O'Hagan   
escribió:



I have several instances of the same generator function running
simultaneously, some within the same process, others in separate  
processes. I

want them to be able to share data (the dictionaries passed to them as
arguments), in such a way that instances designated as "leaders" send  
their

dictionaries to "follower" instances.

I'm trying to use sockets to relay the dicts in pickled form, like this:

from socket import socket

PORT = 2050
RELAY = socket()
RELAY.bind(('', PORT))
RELAY.listen(5)

PICKLEDICT = ''
while 1:
INSTANCE = RELAY.accept()[0]
STRING = INSTANCE.recv(1024)
if STRING == "?":
INSTANCE.send(PICKLEDICT)
else:
PICKLEDICT = STRING

What I was hoping this would do is allow the leaders to send their dicts  
to
this socket and the followers to read them from it after sending an  
initial
"?", and that the same value would be returned for each such query until  
it

was updated.

But clearly I have a fundamental misconception of sockets, as this logic  
only
allows a single query per connection, new connections break the old  
ones, and

a new connection is required to send in a new value.


You may use sockets directly, but instead of building all infrastructure  
yourself, use a ThreadingTCPServer (or ForkingTCPServer), they allow for  
simultaneous request processing. Even setting up a SimpleXMLRPCServer  
(plus either ThreadingMixIn or ForkingMixIn) is easy enough.


Are sockets actually the best way to do this? If so, how to set it up to  
do

what I want? If not, what other approaches could I try?


See the wiki page on distributed systems:  
http://wiki.python.org/moin/DistributedProgramming


--
Gabriel Genellina

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


Re: how can i use lxml with win32com?

2009-10-25 Thread elca

Hello, 
actually what i want is, 
if you run my script you can reach this page
'http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0'
that is korea portal site and i was search keyword using 'korea times'
and i want to scrap resulted to text name with 'blogscrap_save.txt'
if you run this script ,you can see 
following article

"Yesan County: How do you like them apples?
코리아헤럴드 |
carp fishing at the Yedang Reservoir - 
Korea`s biggest - taking a nice stroll... 
During the curator`s recitation of Yun`s life and times as a resistance
and freedom fighter, 
he would emphsize random ...
"

and also can see following article and so on 
"
10,000 Nepalese Diaspora Emerging in Korea
코리아타임스 세계 | 2009.10.23 (금) 오후 9:31
Although the Nepalese community in Korea is worker dominated, 
there are... yoga is popular among Nepalese. These festivals are the 
times when expatriate Nepalese feel nostalgic for their... "

 so actual process to scrap site is,
 first i want to use keyword and want to save resulted article with only
text.
 
 
 i was attached currently im making script but not so much good and can't
work well.
 especially extract part is really hard for novice,such like for me :)
 thanks in advance..
 



http://www.nabble.com/file/p26046215/untitled-1.py untitled-1.py 


motoom wrote:
> 
> elca wrote:
> 
>> actually what i want to parse website is some different language site.
> 
> A different website?  What website?  What text?  Please show your actual 
> use case, instead of smokescreens.
> 
> 
>> so i was quote some common english website for easy understand.   :)
> 
> And, did you learn something from it?  Were you able to apply the 
> technique to the other website?
> 
> 
>> by the way, is it possible to use with PAMIE and beautifulsoup work
>> together?
> 
> If you define 'working together' as like 'PAMIE produces a HTML text and 
> BeautifulSoup parses it', then maybe yes.
> 
> Greetings,
> 
> -- 
> "The ability of the OSS process to collect and harness
> the collective IQ of thousands of individuals across
> the Internet is simply amazing." - Vinod Valloppillil
> http://www.catb.org/~esr/halloween/halloween4.html
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26046215.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: lambda forms within a loop

2009-10-25 Thread Duncan Booth
Michal Ostrowski  wrote:

> def MakeLambdaBad():
>   a = []
>   for x in [1,2]:
>  a.append(lambda q:  x + q)
>   return a

Two things to remember when using lambda:

1. You can always replace lambda with one line function returning the same 
result. The only difference is that you have to give the function a name.
I think using named functions is usually clearer because it makes the code 
look a bit more visually distinct, not just part of some larger expression, 
but YMMV.

So your code could have been written:

def MakeLambdaBad():
  a = []
  for x in [1,2]:
 def baa(q): return x+q
 a.append(baa)
  return a

2. Except for argument defaults it is irrelevant where in a function the 
lambda or def is executed: the code it contains is not evaluated until the 
function is called.

So these are also the same as your original:

def MakeLambdaBad():
  def baa(q): return x+q
  a = []
  for x in [1,2]:
 a.append(baa)
  return a

or if you prefer the lambda:

def MakeLambdaBad():
  baa = lambda q: x+q
  a = []
  for x in [1,2]:
 a.append(baa)
  return a

or if you want the code a bit shorter:

def MakeLambdaBad():
  def baa(q): return x+q
  x = 2
  return [baa, baa]

In case of pedants: when I say irrelevant I mean of course irrelevant so 
long as the function has actually been defined before it is referenced.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread paul

elca schrieb:

Hello,

Hi,


following is script source which can  beautifulsoup and PAMIE work together.
but if i run this script source error was happened.

AttributeError: PAMIE instance has no attribute 'pageText'
File "C:\test12.py", line 7, in 
  bs = BeautifulSoup(ie.pageText()) 
You could execute the script line by line in the python console, then 
after the line "ie = PAMIE(url)" look at the "ie" object with "dir(ie)" 
to check if it really looks like a healthy instance. ...got bored, just 
tried it -- looks like pageText() has been renamed to getPageText().

Try:
text = PAMIE('http://www.cnn.com').getPageText()

cheers
 Paul



and following is orginal source until i was found in internet.

from BeautifulSoup import BeautifulSoup
from PAM30 import PAMIE
url = 'http://www.cnn.com'
ie = PAMIE(url)
bs = BeautifulSoup(ie.pageText())

if possible i really want to make it work together with beautifulsoup or
lxml with PAMIE.
sorry my bad english.
thanks in advance.






Stefan Behnel-3 wrote:

Hi,

elca, 25.10.2009 02:35:

hello...
if anyone know..please help me !
i really want to know...i was searched in google lot of time.
but can't found clear soultion. and also because of my lack of python
knowledge.
i want to use IE.navigate function with beautifulsoup or lxml..
if anyone know about this  or sample.
please help me!
thanks in advance ..

You wrote a message with nine lines, only one of which gives a tiny hint
on
what you actually want to do. What about providing an explanation of what
you want to achieve instead? Try to answer questions like: Where does your
data come from? Is it XML or HTML? What do you want to do with it?

This might help:

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

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






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


Re: how can i use lxml with win32com?

2009-10-25 Thread elca

Hi,
thanks a lot.
studying alone is tough thing :)
how can i improve my skill... 


paul kölle wrote:
> 
> elca schrieb:
>> Hello,
> Hi,
> 
>> following is script source which can  beautifulsoup and PAMIE work
>> together.
>> but if i run this script source error was happened.
>> 
>> AttributeError: PAMIE instance has no attribute 'pageText'
>> File "C:\test12.py", line 7, in 
>>   bs = BeautifulSoup(ie.pageText()) 
> You could execute the script line by line in the python console, then 
> after the line "ie = PAMIE(url)" look at the "ie" object with "dir(ie)" 
> to check if it really looks like a healthy instance. ...got bored, just 
> tried it -- looks like pageText() has been renamed to getPageText().
> Try:
> text = PAMIE('http://www.cnn.com').getPageText()
> 
> cheers
>   Paul
> 
>> 
>> and following is orginal source until i was found in internet.
>> 
>> from BeautifulSoup import BeautifulSoup
>> from PAM30 import PAMIE
>> url = 'http://www.cnn.com'
>> ie = PAMIE(url)
>> bs = BeautifulSoup(ie.pageText())
>> 
>> if possible i really want to make it work together with beautifulsoup or
>> lxml with PAMIE.
>> sorry my bad english.
>> thanks in advance.
>> 
>> 
>> 
>> 
>> 
>> 
>> Stefan Behnel-3 wrote:
>>> Hi,
>>>
>>> elca, 25.10.2009 02:35:
 hello...
 if anyone know..please help me !
 i really want to know...i was searched in google lot of time.
 but can't found clear soultion. and also because of my lack of python
 knowledge.
 i want to use IE.navigate function with beautifulsoup or lxml..
 if anyone know about this  or sample.
 please help me!
 thanks in advance ..
>>> You wrote a message with nine lines, only one of which gives a tiny hint
>>> on
>>> what you actually want to do. What about providing an explanation of
>>> what
>>> you want to achieve instead? Try to answer questions like: Where does
>>> your
>>> data come from? Is it XML or HTML? What do you want to do with it?
>>>
>>> This might help:
>>>
>>> http://www.catb.org/~esr/faqs/smart-questions.html
>>>
>>> Stefan
>>> -- 
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26046638.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Listing variables

2009-10-25 Thread vsoler
Say that a have:

# file test.py
a=7


At the prompt:
import test
dir()

I would like to see the variables created in the test namespace.
However, variable "a" does not appear in the list, only "test". Since
I know that var "a" is reachable from the prompt by means of test.a,
how can I list this sort of variables?

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


Re: A new way to configure Python logging

2009-10-25 Thread Vinay Sajip
Wolodja Wentland  cl.uni-heidelberg.de> writes:

> Could a HTMLHandler be added to the standard set? Preferably one that
> leaves the choice of the template engine to the user.

I haven't done this precisely because users' requirements will be very
different for such a handler. For the same reason, there's no XMLHandler
in the stdlib either. Users can easily define their own handlers to do
whatever they want, which typically will be very application-specific.

> 
> logging.config.fromFiles(['/etc/foo/logging.conf,
>os.path.expanduser(
>'~/.foo/logging.conf')])
> 

I think this sort of requirement varies sufficiently across developers
and applications that it's best not to bake it into the stdlib. With PEP391
developers are free to put together a configuration from whatever sources
and conventions make sense to them, and then expect logging to just follow
instructions which are very specific to logging configuration, and make no
assumptions about company ans application environments and conventions.

> The user adaptations will overrule the defaults in the shipped
> configuration. I know that I could implement that myself using
> {}.update() and the like, but the use case might be common enough to
> justify inclusion in the logging module.
> 

Unfortunately, not in a standard enough way. If in the future it becomes clear
that a standard approach has emerged/evolved, then this can always be added
later.

> I will give an example.. The basic problem I have with *all* config file
> based configuration right now is that I have to *register* every single
> handler/filter with a logger *within* the configuration or their
> configuration will be lost.
[snip]
> In this configuration the handlers will be lost. There is no way to
> retrieve he configured handlers later on. (or is there?).

You are right, unless handlers (and filters, formatters etc.) are given
names which can be used to refer to them across multiple configuration calls.
This is something I am thinking about and will probably update PEP 391
with my thoughts.

> What I would like to do is:
> 
> --- snip ---
> ...
> if options.user_wants_h1:
>   try:
>   someLogger.addHandler(logging.getConfiguredHandler('h1'))
>   except HandlerNotFound as handler_err:
> # handle exception
> 
> if options.user_wants_h2:
>   try:
>   someLogger.addHandler(logging.getConfiguredHandler('h2'))
>   except HandlerNotFound as handler_err:
> # handle exception
> --- snip ---
> 
> ... same for loggers, filters, etc.
> 
> That would enable me to:
> 
> * Create a comprehensive logging building block configuration in its
>   entirety in a nice configuration format. (ie. config file)
> 
> * Easily combine these blocks programmatically

I think your way of working is entirely reasonable, but IMO is not likely to
be so widespread as to make it worthwile baking into the stdlib. You can
easily build your own configuration from which you build the dict to pass
to dictConfig().

> In a way I see three members to the party in the development/usage of
> logging:
> 
> * Logging Expert
> 
>  Will design the logging system for an application/library. Knows the
>  requirements and will be able to design different parts of the system.
>  She will then tell another developer (see below) which blocks are
>  available.
> 
> * Developer
> 
>   A person that knows about the blocks and combines them
>   programmatically, designs the user interface and complains about
>   bugs/new requirements in/for the logging system to the "Logging
>   Expert".
> 
> * User
> 
>   A user gets exposed to different ways in which to change the logging
>   system:
> 
>   - command line options (switches to turn whole blocks off/on)
>   - configuration files
> 
> These *may* a subset of the configuration options that the developer
> wants to expose to the user (format, dateformat, ...)
> (see above)
> 

Those three roles appear reasonable, but I would say that the expert-designed
blocks would be specialised handlers, filters and formatters. That's not a 
full-time job, though ;-)

In addition there are system admin users, who can tweak logging configurations
in response to user community feedback about problems, and to help developers
diagnose faults. In some companies and environments, there are strict walls
between developers and production support teams. In order not to assume too
much about such environmental, non-technical constraints, logging configuration
should not try to be too clever.


Thanks for your thoughts,

Vinay Sajip

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


Re: how can i use lxml with win32com?

2009-10-25 Thread paul

elca schrieb:

Hi,
thanks a lot.
studying alone is tough thing :)
how can i improve my skill... 

1. Stop top-posting.
2. Read documentation
3. Use the interactive prompt

cheers
 Paul




paul kölle wrote:

elca schrieb:

Hello,

Hi,


following is script source which can  beautifulsoup and PAMIE work
together.
but if i run this script source error was happened.

AttributeError: PAMIE instance has no attribute 'pageText'
File "C:\test12.py", line 7, in 
  bs = BeautifulSoup(ie.pageText()) 
You could execute the script line by line in the python console, then 
after the line "ie = PAMIE(url)" look at the "ie" object with "dir(ie)" 
to check if it really looks like a healthy instance. ...got bored, just 
tried it -- looks like pageText() has been renamed to getPageText().

Try:
text = PAMIE('http://www.cnn.com').getPageText()

cheers
  Paul


and following is orginal source until i was found in internet.

from BeautifulSoup import BeautifulSoup
from PAM30 import PAMIE
url = 'http://www.cnn.com'
ie = PAMIE(url)
bs = BeautifulSoup(ie.pageText())

if possible i really want to make it work together with beautifulsoup or
lxml with PAMIE.
sorry my bad english.
thanks in advance.






Stefan Behnel-3 wrote:

Hi,

elca, 25.10.2009 02:35:

hello...
if anyone know..please help me !
i really want to know...i was searched in google lot of time.
but can't found clear soultion. and also because of my lack of python
knowledge.
i want to use IE.navigate function with beautifulsoup or lxml..
if anyone know about this  or sample.
please help me!
thanks in advance ..

You wrote a message with nine lines, only one of which gives a tiny hint
on
what you actually want to do. What about providing an explanation of
what
you want to achieve instead? Try to answer questions like: Where does
your
data come from? Is it XML or HTML? What do you want to do with it?

This might help:

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

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



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






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


Re: Listing variables

2009-10-25 Thread Tim Chase

Say that a have:

# file test.py
a=7


At the prompt:
import test
dir()

I would like to see the variables created in the test namespace.
However, variable "a" does not appear in the list, only "test". Since
I know that var "a" is reachable from the prompt by means of test.a,
how can I list this sort of variables?


  dir(test)

works for any scope you want (except in some C modules...was 
peeved at mod_python for this reason when I was playing with it a 
while back).  I use this for debugging all the time:


  dir(foo.bar.whatever)

or if I want to remember some less-used method on a string/list/dict:

  dir("")
  dir([])
  dir({})

-tkc


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


Re: Python 3.1.1 bytes decode with replace bug

2009-10-25 Thread Dave Angel

Joe wrote:

For the reason BK explained, the important difference is that I ran in
the IDLE shell, which handles screen printing of unicode better ;-)



Something still does not seem right here to me.

In the example above the bytes were decoded to 'UTF-8' with the
  

*nope*  you're decoding FROM utf-8 to unicode.

replace option so any characters that were not UTF-8 were replaced and
the resulting string is '\ufffdabc' as BK explained.  I understand
that the replace worked.

Now consider this:

Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
  

s = '\ufffdabc'
print(s)


Traceback (most recent call last):
  File "", line 1, in 
  File "p:\SW64\Python.3.1.1\lib\encodings\cp437.py", line 19, in
encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in
position
0: character maps to 
  

import sys
sys.getdefaultencoding()


'utf-8'

This too fails for the exact same reason (and doesn't invole decode).

In the original example I decoded to UTF-8 and in this example the
default encoding is UTF-8 so why is cp437 being used?

Thanks in advance for your assistance!


  

Benjamin had it right, but you still don't understand what he said.

The problem in your original example, and in the current one, is not in 
decode(), but in encode(), which is implicitly called by print(), when 
needed to convert from Unicode to some byte format of the console.  Take 
your original example:



 b'\x80abc'.decode('utf-8', 'replace')



The decode() is explicit, and converts *FROM* utf8 string to a unicode 
one.  But since you're running in a debugger, there's an implicit print, 
which is converting unicode into whatever your default console encoding 
is.  That calls encode() (or one of its variants,  charmap_encode(), on 
the unicode string.  There is no relationship between the two steps.


In your current example, you're explicitly doing the print(), but still 
have the same implicit encoding to cp437, which gets the equivalent 
error.  That's the encoding that your Python 3.x is choosing for the 
stdout console, based on country-specific Windows settings.  In the US, 
that implicit encoding is ASCII.  I don't know how to override it 
generically, but I know it's possible to replace stdout with a wrapper 
that does your preferred encoding.  You probably want to keep cp437, but 
change the error handling to ignore.  Or if this is a one-time problem, 
I suspect you could do the encoding manually, to a byte array, then 
print that.


DaveA

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


Re: Listing variables

2009-10-25 Thread Ben Finney
vsoler  writes:

> At the prompt:
> import test
> dir()
>
> I would like to see the variables created in the test namespace.
> However, variable "a" does not appear in the list, only "test". Since
> I know that var "a" is reachable from the prompt by means of test.a,
> how can I list this sort of variables?

>>> help(dir)
Help on built-in function dir in module __builtin__:

dir(...)
dir([object]) -> list of strings

Return an alphabetized list of names comprising (some of) the
attributes
of the given object, and of attributes reachable from it:

No argument:  the names in the current scope.
Module object:  the module attributes.
[…]

So ‘dir()’ returns the names in the current scope, which is why the
names in the module ‘test’ don't appear there.

-- 
 \  “What I have to do is see, at any rate, that I do not lend |
  `\  myself to the wrong which I condemn.” —Henry Thoreau, _Civil |
_o__)Disobedience_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread elca



paul kölle wrote:
> 
> elca schrieb:
>> Hi,
>> thanks a lot.
>> studying alone is tough thing :)
>> how can i improve my skill... 
> 1. Stop top-posting.
> 2. Read documentation
> 3. Use the interactive prompt
> 
> cheers
>   Paul
> 
>> 
>> 
>> paul kölle wrote:
>>> elca schrieb:
 Hello,
>>> Hi,
>>>
 following is script source which can  beautifulsoup and PAMIE work
 together.
 but if i run this script source error was happened.

 AttributeError: PAMIE instance has no attribute 'pageText'
 File "C:\test12.py", line 7, in 
   bs = BeautifulSoup(ie.pageText()) 
>>> You could execute the script line by line in the python console, then 
>>> after the line "ie = PAMIE(url)" look at the "ie" object with "dir(ie)" 
>>> to check if it really looks like a healthy instance. ...got bored, just 
>>> tried it -- looks like pageText() has been renamed to getPageText().
>>> Try:
>>> text = PAMIE('http://www.cnn.com').getPageText()
>>>
>>> cheers
>>>   Paul
>>>
 and following is orginal source until i was found in internet.

 from BeautifulSoup import BeautifulSoup
 from PAM30 import PAMIE
 url = 'http://www.cnn.com'
 ie = PAMIE(url)
 bs = BeautifulSoup(ie.pageText())

 if possible i really want to make it work together with beautifulsoup
 or
 lxml with PAMIE.
 sorry my bad english.
 thanks in advance.






 Stefan Behnel-3 wrote:
> Hi,
>
> elca, 25.10.2009 02:35:
>> hello...
>> if anyone know..please help me !
>> i really want to know...i was searched in google lot of time.
>> but can't found clear soultion. and also because of my lack of python
>> knowledge.
>> i want to use IE.navigate function with beautifulsoup or lxml..
>> if anyone know about this  or sample.
>> please help me!
>> thanks in advance ..
> You wrote a message with nine lines, only one of which gives a tiny
> hint
> on
> what you actually want to do. What about providing an explanation of
> what
> you want to achieve instead? Try to answer questions like: Where does
> your
> data come from? Is it XML or HTML? What do you want to do with it?
>
> This might help:
>
> http://www.catb.org/~esr/faqs/smart-questions.html
>
> Stefan
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>
>
>>> -- 
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 


hello,
im sorry ,also im not familiar with newsgroup.
so this position is bottom-posting position? 
if wrong correct me..
thanks , in addition i was testing just before you sent 

text = PAMIE('http://www.naver.com').getPageText() 
i have some question...
how can i keep open only one windows? not open several windows.
following is my scenario.
after open www.cnn.com i want to go
http://www.cnn.com/2009/US/10/24/teen.jane.doe/index.html
with keep only one windows.

text = PAMIE('http://www.cnn.com').getPageText() 
sleep(5)
text = PAMIE('http://www.cnn.com/2009/US/10/24/teen.jane.doe/index.html')
thanks in advance :)


-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26046897.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Listing variables

2009-10-25 Thread Dave Angel

vsoler wrote:

Say that a have:

# file test.py
a=7


At the prompt:
import test
dir()

I would like to see the variables created in the test namespace.
However, variable "a" does not appear in the list, only "test". Since
I know that var "a" is reachable from the prompt by means of test.a,
how can I list this sort of variables?

Vicente Soler

  

dir(test)


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


Ctypes and Structures

2009-10-25 Thread Martijn Arts
I'm working with ctypes on a bridge (?) from WiiUse; a new and improved
PyWiiUse, but I'm having a problem:

When connecting to the wiimotes with the init function it gives me back
an array with pointers. Every pointer points to a WiiMote structure, this
all
goes well.
Now when trying to poll the wiimotes (check for events like button presses)
it should edit the WiiMote structures where's button presses using
bit-flags,
but it doesn't.

Here's a bit of code:
wiimotes = pywiiuse.init(1) # connect to the wiimotes
(...)
pywiiuse.rumble(wiimotes[0], 1) # little example of how it works

init function:
def init(nwiimotes):
c_array = wiimote_p * nwiimotes
wiiusedll.wiiuse_init.restype = c_array
return wiiusedll.wiiuse_init(c_int(nwiimotes))

Now I'm going to poll it:

while True:
if pywiiuse.poll(wiimotes, 1):
i = 0
while i < 1:
print 'EVENT:'
print pywiiuse.is_pressed(wiimotes[0], pywiiuse.button['Right'])
i += 1

pywiiuse.button['Right']is 0x0200

This is the is_pressed function:
def is_pressed(dev, button):
return (dev.contents.btns & button) == button

To be honest: I have no idea what is_pressed actually does, but it should
return True
or False?

After testing around a bit I found out that dev.contents.btns always equals
420.

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


python3 Unicode is slow

2009-10-25 Thread Dale Gerdemann
I've written simple code in 2.6 and 3.0 to read every charcter of a
set of files and print out some information for each of these
characters. I tested each program on a large Cyrillic/Latin text. The
result was that the 2.6 version was about 5x faster. Here are the two
programs:

#!/usr/bin/env python

import sys
import codecs
import unicodedata
for path in sys.argv[1:]:
lines = codecs.open(path, encoding='UTF-8',
errors='replace').readlines()

for line in lines:
for c in line:
name = unicodedata.name(c,'unknown')
prnt = prnt_rep = c.encode('utf8')
if name == 'unknown':
prnt = ' '
if ord(c) > 127:
print('%s %-14r U+%04x %s' % (prnt, prnt_rep, ord(c),
name))
else:
if ord(c) == 9:
name = 'tab'
prnt = ' '
elif ord(c) == 10:
name = 'LF'
prnt = ' '
elif ord(c) == 13:
name = 'CR'
prnt = ' '
print("{0:s} '\\x{1:02x}' U+{2:04x}
{3:s}".format(
prnt, ord(c), ord(c), name))


#!/usr/bin/env python3

import sys
import unicodedata

for path in sys.argv[1:]:
lines = open(path, errors='replace').readlines()

for line in lines:
for c in line:
code_point = ord(c)
utf8 = c.encode()
if ord(c) <= 127:
utf8 = "b'\\" + hex(ord(c))[1:] + "'"
name = unicodedata.name(c,'unknown')
if name == 'unknown':
c = ' '
if code_point == 9:
c = ' '
name = 'tab'
elif code_point == 10:
c = ' '
name = 'LF'
elif code_point == 13:
c = ' '
name = 'CR'
print("{0:s} {1:15s} U+{2:04x} {3:s}".format(
c, utf8, code_point, name))


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


Re: Listing variables

2009-10-25 Thread vsoler
On Oct 25, 12:01 pm, Tim Chase  wrote:
> > Say that a have:
>
> > # file test.py
> > a=7
>
> > At the prompt:
> > import test
> > dir()
>
> > I would like to see the variables created in the test namespace.
> > However, variable "a" does not appear in the list, only "test". Since
> > I know that var "a" is reachable from the prompt by means of test.a,
> > how can I list this sort of variables?
>
>    dir(test)
>
> works for any scope you want (except in some C modules...was
> peeved at mod_python for this reason when I was playing with it a
> while back).  I use this for debugging all the time:
>
>    dir(foo.bar.whatever)
>
> or if I want to remember some less-used method on a string/list/dict:
>
>    dir("")
>    dir([])
>    dir({})
>
> -tkc

Tim,

If I just input dir(test) I don't get "a" in my list.

>>> import test
>>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'__path__']
>>>

I am using python 2.6

Am I doing anything wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A new way to configure Python logging

2009-10-25 Thread Wolodja Wentland
On Sun, Oct 25, 2009 at 10:48 +, Vinay Sajip wrote:
> Wolodja Wentland  cl.uni-heidelberg.de> writes:
[ HTMLHandler, multiple configuration files ]

OK! I agree that these parts are hard to standardise and do not really
belong in the *logging* module. 

Maybe a kind soul implements a "configuration" module in the future that
accepts configuration files in a plethora of formats and uses
dictionaries as the lingua franca for final configuration.

> > I will give an example.. The basic problem I have with *all* config file
> > based configuration right now is that I have to *register* every single
> > handler/filter with a logger *within* the configuration or their
> > configuration will be lost.

> You are right, unless handlers (and filters, formatters etc.) are given
> names which can be used to refer to them across multiple configuration calls.
> This is something I am thinking about and will probably update PEP 391
> with my thoughts.

[ usage example ]

> I think your way of working is entirely reasonable, but IMO is not likely to
> be so widespread as to make it worthwile baking into the stdlib. You can
> easily build your own configuration from which you build the dict to pass
> to dictConfig().

Are these two statements not a bit contradictory? If it would be
possible to refer to all major components in logging by *unique* names
would that not mean that the usage example I gave is possible?

I think we managed to single out the sole requirement I would have
towards 'logging' that is missing today.

Id est: The possibility to refer/retrieve/... all major components used
by logging (loggers, handlers, filters, formatters, adaptors) by a
*unique* name. That would enable the developer to deal with them in a
consistent way irregardless of the way they were initially defined
(configuration file, programmatically).

Is this way to deal with logging really that uncommon? I guess I have
to read a lot code to see how other people do it as this would be the
way that feels most natural to me.

BTW, the LoggerAdaptor class looks really useful. I just discovered it
and I have the feeling that I might use it frequently.

> > * Logging Expert
> > * Developer
> > * User

> Those three roles appear reasonable, but I would say that the expert-designed
> blocks would be specialised handlers, filters and formatters. That's not a 
> full-time job, though ;-)

I completely agree. I know that the logging expert and the developer
will most likely be the same person. I just wanted to point out that the
design of the logging system and its components is a different step in
program development than the usage of said system by a developer and
different users.

Thanks again for taking this discussion to the users list. I could have
commented in the -dev thread, but did not. (I ask myself: Why?) I
therefore appreciate it a lot that you try to figure out your users
requirements before implementing them! I just love open source software!

Have a great day and let me know whatever you come up with. 

Wolodja


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listing variables

2009-10-25 Thread Tim Chase

If I just input dir(test) I don't get "a" in my list.


import test
dir(test)

['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'__path__']

I am using python 2.6

Am I doing anything wrong?



Are you importing the module you think you are?

t...@rubbish:~/tmp$ echo "a=42" > test.py
t...@rubbish:~/tmp$ python2.5
>>> import test
>>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', 'a']


Granted this is 2.5 (the most current I have on my Debian box, 
but I also tested in 2.3 and 2.4 which are also installed) 
instead of 2.6 but they should all behave the same.  If I remove 
test.py/test.pyc, I get the following:


t...@rubbish:~/tmp$ rm test.py test.pyc
t...@rubbish:~/tmp$ python2.5
>>> import test
>>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', '__path__']
>>> test.__file__
'/usr/lib/python2.5/test/__init__.pyc'

because there's apparently a module named "test" in the standard 
distribution that gets found instead.


-tkc



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


Re: python3 Unicode is slow

2009-10-25 Thread John Machin
On Oct 25, 11:12 pm, Dale Gerdemann 
wrote:
> I've written simple code in 2.6 and 3.0 to read every charcter of a
> set of files and print out some information for each of these
> characters. I tested each program on a large Cyrillic/Latin text. The
> result was that the 2.6 version was about 5x faster.

3.0? Nowadays nobody wants to know about benchmarks of 3.0. Much of
the new 3.X file I/O stuff was written in Python. It has since been
rewritten in C. In general AFAICT there is no good reason to be using
3.0. Consider updating to 3.1.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


im sorry ,also im not familiar with newsgroup.


It's not a newsgroup, but a mailing list. And if you're new to a certain 
community you're not familiar with, it's best to lurk a few days to see 
how it is used.



so this position is bottom-posting position? 


It is, but you should also cut away any quoted text that is not directly 
related to the answer.
Otherwise people have to scroll many screens full of text before they 
can see the answer.



> how can i keep open only one windows? not open several windows.

The trick is to not instantiate multiple PAMIE objects, but only once, 
and reuse that.

Like:

import time
import PAM30
ie=PAM30.PAMIE( )

ie.navigate("http://www.cnn.com";)
text1=ie.getPageText()

ie.navigate("http://www.nu.nl";)
text2=ie.getPageText()

ie.quit()
print len(text1), len(text2)


But still I think it's unnecessary to use Internet Explorer to get 
simple web pages.
The standard library "urllib2.urlopen()" works just as well, and doesn't 
rely on Internet Explorer to be present.


Greetings,


--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: A new way to configure Python logging

2009-10-25 Thread Vinay Sajip
Wolodja Wentland  cl.uni-heidelberg.de> writes:

> > You are right, unless handlers (and filters, formatters etc.) are given
> > names which can be used to refer to them across multiple configuration 
> > calls.
> > This is something I am thinking about and will probably update PEP 391
> > with my thoughts.
> 
> Are these two statements not a bit contradictory? If it would be
> possible to refer to all major components in logging by *unique* names
> would that not mean that the usage example I gave is possible?

Perhaps, depending on the scheme I come up with.

> I think we managed to single out the sole requirement I would have
> towards 'logging' that is missing today.

Named items will certainly make more things possible, and so I am thinking more
seriously about it. I will post here once I've updated PEP 391 with my thoughts.

> Is this way to deal with logging really that uncommon? I guess I have
> to read a lot code to see how other people do it as this would be the
> way that feels most natural to me.

It could be not uncommon, without being common ;-) There are lots of open
source projects around, from some of which (hopefully) you can see what
approaches others have taken.

> Thanks again for taking this discussion to the users list. I could have
> commented in the -dev thread, but did not. (I ask myself: Why?) I
> therefore appreciate it a lot that you try to figure out your users
> requirements before implementing them! I just love open source software!

Well, thanks for responding in such detail, and I hope more people give their
input because it would be a real shame (if they care) not to take the
opportunity to give some feedback. The PEP is perhaps "too much information"
for casual users to bother with, but (as Nick Coghlan said on the dev list)
it's worth putting in the thought a PEP requires, just so that if the
configuration approach is standardised, at least it has had the opportunity
for committer and community review first.

Best regards,


Vinay Sajip


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


Re: how can i use lxml with win32com?

2009-10-25 Thread Michiel Overtoom

elca wrote:


http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0
that is korea portal site and i was search keyword using 'korea times'
and i want to scrap resulted to text name with 'blogscrap_save.txt'


Aha, now we're getting somewhere.

Getting and parsing that page is no problem, and doesn't need JavaScript 
or Internet Explorer.


import urllib2
import BeautifulSoup
doc=urllib2.urlopen("http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0";)
soup=BeautifulSoup.BeautifulSoup(doc)


By analyzing the structure of that page you can see that the articles 
are presented in an unordered list which has class "type01".  The 
interesting bit in each list item is encapsulated in a  tag with 
class "sh_news_passage".  So, to parse the articles:


ul=soup.find("ul","type01")
for li in ul.findAll("li"):
dd=li.find("dd","sh_news_passage")
print dd.renderContents()
print

This example prints them, but you could also save them to a file (or a 
database, whatever).


Greetings,



--
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can i use lxml with win32com?

2009-10-25 Thread Irmen de Jong

Michiel Overtoom wrote:

elca wrote:


im sorry ,also im not familiar with newsgroup.


It's not a newsgroup, but a mailing list. And if you're new to a certain 
community you're not familiar with, it's best to lurk a few days to see 
how it is used.


Pot. Kettle. Black.
comp.lang.python really is a usenet news group. There is a mailing list that mirrors the 
newsgroup though.


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


Re: Listing variables

2009-10-25 Thread vsoler
On Oct 25, 1:32 pm, Tim Chase  wrote:
> > If I just input dir(test) I don't get "a" in my list.
>
>  import test
>  dir(test)
> > ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
> > '__path__']
>
> > I am using python 2.6
>
> > Am I doing anything wrong?
>
> Are you importing the module you think you are?
>
> t...@rubbish:~/tmp$ echo "a=42" > test.py
> t...@rubbish:~/tmp$ python2.5
>  >>> import test
>  >>> dir(test)
> ['__builtins__', '__doc__', '__file__', '__name__', 'a']
>
> Granted this is 2.5 (the most current I have on my Debian box,
> but I also tested in 2.3 and 2.4 which are also installed)
> instead of 2.6 but they should all behave the same.  If I remove
> test.py/test.pyc, I get the following:
>
> t...@rubbish:~/tmp$ rm test.py test.pyc
> t...@rubbish:~/tmp$ python2.5
>  >>> import test
>  >>> dir(test)
> ['__builtins__', '__doc__', '__file__', '__name__', '__path__']
>  >>> test.__file__
> '/usr/lib/python2.5/test/__init__.pyc'
>
> because there's apparently a module named "test" in the standard
> distribution that gets found instead.
>
> -tkc

Tim,

You were right. When I renamed my test.py file into test77.py it
worked perfectly well. Thank you.

Is there a way to know which test.py it was importing?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quit button

2009-10-25 Thread John Posner

linda.s wrote:


When I click "quit" button, why the following code has problem?

from Tkinter import *
colors = ['red', 'green', 'yellow', 'orange', 'blue', 'navy']

def gridbox(parent):
r = 0
for c in colors:
l = Label(parent, text=c, relief=RIDGE,  width=25)
e = Entry(parent, bg=c,   relief=SUNKEN, width=50)
l.grid(row=r, column=0)
e.grid(row=r, column=1)
r = r+1

def packbox(parent):
for c in colors:
f = Frame(parent)
l = Label(f, text=c, relief=RIDGE,  width=25)
e = Entry(f, bg=c,   relief=SUNKEN, width=50)
f.pack(side=TOP)
l.pack(side=LEFT)
e.pack(side=RIGHT)

if __name__ == '__main__':
root = Tk()
gridbox(Toplevel())
packbox(Toplevel())
Button(root, text='Quit', command=root.quit).pack()
mainloop()
  
Please describe the problem in more detail. Including the exact error 
message, if any, would be very helpful. When I ran this code on Python 
2.6.3rc1 / Windows XP, clicking "Quit" closed all three windows and 
ended the program. (BTW, nice use of both LEFT and RIGHT packing!)


-John

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


Re: quit button

2009-10-25 Thread Grant Edwards
On 2009-10-25, linda.s  wrote:

> When I click "quit" button, why the following code has problem?

It works fine for me (running Gentoo Linux on IA32).

-- 
Grant

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


Re: PySerial

2009-10-25 Thread Ronn Ross
On Sat, Oct 24, 2009 at 4:53 PM, John Nagle  wrote:

> Gabriel Genellina wrote:
>
>> En Fri, 23 Oct 2009 20:56:21 -0300, Ronn Ross 
>> escribió:
>>
>>
>>  I have tried setting the baud rate with no success. Also I'm using port
>>> #2
>>> because I"m using a usb to serial cable.
>>>
>>
>> Note that Serial(2) is known as COM3 in Windows, is it ok?
>>
>
>  Do you have a machine with a COM3 port?
>
>John Nagle

Yes, I have verified that there is a COM3. I connected to it using puTTY. I
was able to access the device from puTTY.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listing variables

2009-10-25 Thread Tim Chase

t...@rubbish:~/tmp$ rm test.py test.pyc
t...@rubbish:~/tmp$ python2.5
 >>> import test
 >>> dir(test)
['__builtins__', '__doc__', '__file__', '__name__', '__path__']
 >>> test.__file__
'/usr/lib/python2.5/test/__init__.pyc'

because there's apparently a module named "test" in the standard
distribution that gets found instead.


You were right. When I renamed my test.py file into test77.py it
worked perfectly well. Thank you.

Is there a way to know which test.py it was importing?


well, as my simple code showed, you can check test.__file__ or
test.__path__ if you're curious.  Python just searches through 
your $PYTHONPATH which you can determine at runtime via sys.path


-tkc


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


Solving System of Linear Equation (SLE) - FuncDesigner example

2009-10-25 Thread dmitrey
Hi all,
I would like to introduce a couple examples of easy & convenient
modelling and solving System of Linear Equation (SLE) by FuncDesigner
(a python-written tool, BSD license). It doesn't require to construct
matrices A and b (Ax = b) by user, they are created automatically. See
here for details:
http://openopt.org/FuncDesignerDoc#Solving_systems_of_linear_equations
Currently the only one solver available is numpy.linalg.solve (LAPACK
routine dgesv, dense systems only); I intend to add some more solvers,
maybe for sparse matrices as well, in future.
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Oct 25)

2009-10-25 Thread Cameron Laird
QOTW:  "It was intended to be understood, not copied." - Dave Angel
comments
on a characteristic of didactic examples
   http://groups.google.com/group/comp.lang.python/msg/61e2d60d08f1c630


   Altering the default character encoding (sys.setdefaultencoding) is
never
   a  good idea:
   ^://groups.google.com/group/comp.lang.python/t/
ecc3671082f897b4/

   How come id() returns the same thing for different objects?
   ^://groups.google.com/group/comp.lang.python/t/
bc09c37fc40059ac/

   Some iterators share state, while others don't - why?
   ^://groups.google.com/group/comp.lang.python/t/
d463230d1752aa7f/

   sum(list_of_strings) is explicitely forbidden - why?
   ^://groups.google.com/group/comp.lang.python/t/
f3c0fba5305e11e2/

   Neither __getattribute__ nor metaclasses can be used to implement
   __special__ methods:
   ^://groups.google.com/group/comp.lang.python/t/
f0a5aeb35f946f80/

   How to compute a running median efficiently:
   ^://groups.google.com/group/comp.lang.python/t/
d0e011c87174c2d0/

   Several details on how str.split() works are not adequately
documented:
   ^://groups.google.com/group/comp.lang.python/t/
26dff8570a79067d/

   How to implement a set that uses a custom function to determine
element
   membership (not the element's __eq__):
   ^://groups.google.com/group/comp.lang.python/t/
7eb4d6db8556f870/

   Generators explained as simply as possible:
   ^://groups.google.com/group/comp.lang.python/t/
70a954d0e034b84c/

   Proposal to add slice notation [start:stop:step] to iterators/
generators:
   ^://groups.google.com/group/comp.lang.python/t/
440076d71746f8cf/

   An encoding problem involves an XML document, HTTP headers, and
Google
   servers:
   ^://groups.google.com/group/comp.lang.python/t/
885c62699b434d25/

   The `while True:` idiom makes the longest thread so far:
   ^://groups.google.com/group/comp.lang.python/t/
46a2082b2e2c991c/

   "Homework" questions: what should be our reaction?
   ^://groups.google.com/group/comp.lang.python/t/
f7a8c5107e9d27bf/

   Why is python so sad :( ?
   ^://groups.google.com/group/comp.lang.python/t/
60c39c1ab1b39ef9/

   Guido's proposes to freeze language grammar and semantics for
several
   years:
   ^://comments.gmane.org/gmane.comp.python.ideas/6282



Everything Python-related you want is probably one or two clicks away
in
these pages:

   Python.org's Python Language Website is the traditional
   center of Pythonia
   http://www.python.org
   Notice especially the master FAQ
   http://www.python.org/doc/FAQ.html

   PythonWare complements the digest you're reading with the
   marvelous daily python url
http://www.pythonware.com/daily

   Just beginning with Python?  This page is a great place to start:
   http://wiki.python.org/moin/BeginnersGuide/Programmers

   The Python Papers aims to publish "the efforts of Python
enthusiasts":
   http://pythonpapers.org/
   The Python Magazine is a technical monthly devoted to Python:
   http://pythonmagazine.com

   Readers have recommended the "Planet" site:
   http://planet.python.org

   comp.lang.python.announce announces new Python software.  Be
   sure to scan this newsgroup weekly.
   http://groups.google.com/group/comp.lang.python.announce/topics

   Python411 indexes "podcasts ... to help people learn Python ..."
   Updates appear more-than-weekly:
   http://www.awaretek.com/python/index.html

   The Python Package Index catalogues packages.
   http://www.python.org/pypi/

   Much of Python's real work takes place on Special-Interest Group
   mailing lists
   http://www.python.org/sigs/

   Python Success Stories--from air-traffic control to on-line
   match-making--can inspire you or decision-makers to whom you're
   subject with a vision of what the language makes practical.
   http://www.pythonology.com/success

   The Python Software Foundation (PSF) has replaced the Python
   Consortium as an independent nexus of activity.  It has official
   responsibility for Python's development and maintenance.
   http://www.python.org/psf/
   Among the ways you can support PSF is with a donation.
   http://www.python.org/psf/donations/

   The Summary of Python Tracker Issues is an automatically generated
   report summarizing new bugs, closed ones, and patch submissions.
   
http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

   Although unmaintained since 2002, the Cetus collection of Python
   hyperlinks retains a few gems.
   http://www.cetus-links.org/oo_python.html

   Python FAQTS
   http://python.faqts.com/

   The Cookbook is a collaborative effort to capture useful and
   interesting recipes.
   http://code.activestate.com/recipes/langs/python/

   Many Python conferences around the world are in preparation.
   Watch this spa

Python-URL! - weekly Python news and links (Oct 25)

2009-10-25 Thread Gabriel Genellina
QOTW:  "It was intended to be understood, not copied." - Dave Angel comments
on a characteristic of didactic examples
http://groups.google.com/group/comp.lang.python/msg/61e2d60d08f1c630


Altering the default character encoding (sys.setdefaultencoding) is never
a  good idea:
^://groups.google.com/group/comp.lang.python/t/ecc3671082f897b4/

How come id() returns the same thing for different objects?
^://groups.google.com/group/comp.lang.python/t/bc09c37fc40059ac/

Some iterators share state, while others don't - why?
^://groups.google.com/group/comp.lang.python/t/d463230d1752aa7f/

sum(list_of_strings) is explicitely forbidden - why?
^://groups.google.com/group/comp.lang.python/t/f3c0fba5305e11e2/

Neither __getattribute__ nor metaclasses can be used to implement
__special__ methods:
^://groups.google.com/group/comp.lang.python/t/f0a5aeb35f946f80/

How to compute a running median efficiently:
^://groups.google.com/group/comp.lang.python/t/d0e011c87174c2d0/

Several details on how str.split() works are not adequately documented:
^://groups.google.com/group/comp.lang.python/t/26dff8570a79067d/

How to implement a set that uses a custom function to determine element
membership (not the element's __eq__):
^://groups.google.com/group/comp.lang.python/t/7eb4d6db8556f870/

Generators explained as simply as possible:
^://groups.google.com/group/comp.lang.python/t/70a954d0e034b84c/

Proposal to add slice notation [start:stop:step] to iterators/generators:
^://groups.google.com/group/comp.lang.python/t/440076d71746f8cf/

An encoding problem involves an XML document, HTTP headers, and Google
servers:
^://groups.google.com/group/comp.lang.python/t/885c62699b434d25/

The `while True:` idiom makes the longest thread so far:
^://groups.google.com/group/comp.lang.python/t/46a2082b2e2c991c/

"Homework" questions: what should be our reaction?
^://groups.google.com/group/comp.lang.python/t/f7a8c5107e9d27bf/

Why is python so sad :( ?
^://groups.google.com/group/comp.lang.python/t/60c39c1ab1b39ef9/

Guido's proposes to freeze language grammar and semantics for several
years:
^://comments.gmane.org/gmane.comp.python.ideas/6282



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiasts":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes

Re: Listing variables

2009-10-25 Thread vsoler
On Oct 25, 5:07 pm, Tim Chase  wrote:
> >> t...@rubbish:~/tmp$ rm test.py test.pyc
> >> t...@rubbish:~/tmp$ python2.5
> >>  >>> import test
> >>  >>> dir(test)
> >> ['__builtins__', '__doc__', '__file__', '__name__', '__path__']
> >>  >>> test.__file__
> >> '/usr/lib/python2.5/test/__init__.pyc'
>
> >> because there's apparently a module named "test" in the standard
> >> distribution that gets found instead.
>
> > You were right. When I renamed my test.py file into test77.py it
> > worked perfectly well. Thank you.
>
> > Is there a way to know which test.py it was importing?
>
> well, as my simple code showed, you can check test.__file__ or
> test.__path__ if you're curious.  Python just searches through
> your $PYTHONPATH which you can determine at runtime via sys.path
>
> -tkc

Thank you Tim, everything is clear now.

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


OT Virtual Server Host

2009-10-25 Thread Victor Subervi
Hi;
Completely OT, but my back's up against the wall. I'm convinced that the
reason my codes keep breaking--and even stable installations of s/w from
SourceForge such as SimpleMail--on the hosts I've been using is because
their hardware should have conservatively been trashed 5 years ago. It's
simply impossible to code around garbage. My ultimate solution will be to
colo two of my own servers (for redundancy), but for a few months while I
get built back up, I still need to find some place where I can get my
client's sites up and running or I'll never be able to earn a paycheck. I'm
more than happy to pay $100/mo or even more. I don't want one of those
$99/mo dedicated server plans, either, because their hardware is trash too.
I've been in this game long enough to figure these guys out. What I need is
a virtual server with some small company that has hardware that was
purchased in this century not the last one. But I don't know where to find
the same. Google just brings up all the GoDaddys and eNoms of the world. Any
ideas?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Extracting text using Beautifulsoup

2009-10-25 Thread TC

Greetings all.

Working with data from 'http://www.finviz.com/quote.ashx?t=SRS',  I was able 
to  get the info using re, however I thought using Beautifulsoup a more 
elegant approach.

Having a bit of a problem though...

Trying to extract text:

SMA20 -1.77%
SMA50 -9.73%

utilizing attribute body in Average] >


From:
---HTML 
snippet
 title="cssbody=[tooltip_short_bdy] cssheader=[tooltip_short_hdr] 
body=[Distance from 20-Day Simple Moving Average] offsetx=[10] offsety=[20] 
delay=[300]">

  SMA20
 
 
  
   
-1.77%
   
  
 
 title="cssbody=[tooltip_short_bdy] cssheader=[tooltip_short_hdr] 
body=[Distance from 50-Day Simple Moving Average] offsetx=[10] offsety=[20] 
delay=[300]">

  SMA50
 
 
  
   
-9.73%
   
  
 
---HTML 
snippet

Using:

import urllib
from BeautifulSoup import BeautifulSoup
archives_url = 'http://www.finviz.com/quote.ashx?t=SRS'
archives_html = urllib.urlopen(archives_url).read()
soup = BeautifulSoup(archives_html)
t = soup.findAll('table')
for table in t:
   g.write(str(table.name) + '\r\n')
   rows = table.findAll('tr')
   for tr in rows:
   g.write('\r\n\t')
   cols = tr.findAll('td')
   for td in cols:
   ret = str(td.find(name='title'))
   g.write('\t\t' + str(td) + '\r\n')
g.close()

Total failure of course.
Any ideas?
Thanks in advance... 


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


virtualenv under Win7: easy_install fails in virtual environments

2009-10-25 Thread Guillermo
Hi,

I've installed setuptools for my default python installation and it
works perfectly without even asking for admin credentials to install
packages.

After that I've installed virtualenv.

If I do:

>>> virtualenv x

... a new virtual environment is created, but whenever I try to run
easy_install within the new virtual environment, I'm prompted to enter
my admin password (I'm running as "Power User" normally) and
easy_install fails complaining that "Can't find D:/correct/path/to/
virtualenv/Scripts/python.exe". This path is private to my normal, non-
admin account.

It also fails if I'm running as an administrator and perform the same
steps.

I've tried runas to no avail too.

Is this a known issue?

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


Re: lambda forms within a loop

2009-10-25 Thread Scott David Daniels

Michal Ostrowski wrote:

...
[a,b] = MakeLambda()
print a(10)
print b(10)


Here is yet another way to solve the problem:

import functools
def AddPair(x, q):
return x + q
a, b = [functools.partial(AddPair, x) for x in [1, 2]]
print a(10)
print b(10)

Or even, since these are numbers:
a, b = [x.__add__ for x in [1, 2]]
print a(10)
print b(10)

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda forms within a loop

2009-10-25 Thread Paul Rubin
Michal Ostrowski  writes:
> def MakeLambdaBad():
>   a = []
>   for x in [1,2]:
>  a.append(lambda q:  x + q)
>   return a

The problem here is that x is a free variable in the lambdas that you
put in a.  When you actually evaluate those lambdas, they use whatever
the value of x happens to be at that time.  The cure is:

   for x in [1,2]:
  a.append(lambda q, x=x:  x + q)

This creates an additional binding inside the lambda, that captures
the value of the loop index when the lambda is made.
-- 
http://mail.python.org/mailman/listinfo/python-list


python web service or Apache?

2009-10-25 Thread Peng Yu
Although, python can be used to provide web service. The following
webpage also mentioned, "Apache the best and most widely used web
server on the Internet today, check it out. If you want to run your
own web server this is the one to get, you can get binaries for both
Windows and Unix. You can download the entire sourcecode if you want
to check how it was made." Therefore, it would be better to use Apache
rather than python to provide web service, right?

http://fragments.turtlemeat.com/pythonwebserver.php
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is __mul__ sufficient for operator '*'?

2009-10-25 Thread Mick Krippendorf
Muhammad Alkarouri schrieb:
> I was having a go at a simple implementation of Maybe in Python when I
> stumbled on a case where x.__mul__(y) is defined while x*y is not.
> 
> class Maybe(object):
> def __init__(self, obj):
> self.o = obj
> def __repr__(self):
> return 'Maybe(%s)' % object.__getattribute__(self, "o")
> def __getattribute__(self, name):
> try:
> o = object.__getattribute__(self, "o")
> r = getattr(o,name)
> if callable(r):
> f = lambda *x:Maybe(r(*x))
> return f
> else:
> return Maybe(r)
> except:
> return Maybe(None)
> 
 x=Maybe(9)
 x.__mul__(7)
> Maybe(63)
 x*7
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> x*7
> TypeError: unsupported operand type(s) for *: 'Maybe' and 'int'

Here's how I'd do it. It will not win a beauty contest any time soon,
but at least it's a workaround:

8<8<8<8<8<8<8<

def meta(lift, lifted, not_lifted=[]):
not_lifted = list(not_lifted) + object.__dict__.keys()
class MetaMaybe(type):
def __new__(meta, mcls, bases, dct):
dct.update(
(name, lift(name))
for name in set(lifted) - set(not_lifted)
)
return type(mcls, bases, dct)
return MetaMaybe

class Nothing(object):
__metaclass__ = meta(lambda name: lambda self, *a, **k: self, (
"__add__", "__sub__", "__mul__", "__div__", "__truediv__",
"__floordiv__", "__divmod__", "__radd__", "__rsub__",
"__rmul__", "__rdiv__", "__rtruediv__", "__rfloordiv__",
"__rdivmod__", "__rshift__", "__lshift__", "__call__",
# and so on, for every special method that Nothing knows
))
def __new__(cls, value=None):
try: # singleton
return cls.value
except AttributeError:
cls.value = super(Nothing, cls).__new__(cls)
return cls.value
def __str__(self):
return "Nothing"
__repr__ = __str__

Nothing = Nothing()

def just(vcls):
def lifter(name):
attr = getattr(vcls, name)
def lifted(self, *ms):
try:
return self.lift(attr)(self, *ms)
except:
return Nothing
return lifted
class Just(object):
__metaclass__ = meta(lifter, vcls.__dict__.keys())
def __new__(cls, value):
if value in (Nothing, NotImplemented):
return Nothing
return super(Just, cls).__new__(cls)
def __init__(self, value):
self.value = value
def __str__(self):
return "Just(%s)" % self.value
@classmethod
def lift(c, f):
return lambda *ms:c(f(*(m.value for m in ms)))
return Just

from collections import defaultdict

class TypeDict(defaultdict):
def __missing__(self, key):
if self.default_factory is None:
raise KeyError(key)
return self.default_factory(key)

class Maybe(object):
typemap = TypeDict(just)
def __new__(cls, value):
return Maybe.typemap[value.__class__](value)

def foo(x, y):
return x * 2 + y * 3

if __name__ == "__main__":

print Maybe(Nothing)
print Maybe(1) / Maybe(0)
print Maybe(10.) * Maybe(5) / Maybe(2) ** Maybe(3)
print Maybe(foo)(Maybe(6), Maybe(10))
print Maybe("hello").upper()
print Maybe("hello").startswith(Maybe("h"))
print getattr(Maybe("hello"), "startswith")(Maybe("h"))
print Maybe(foo)(Maybe("hello! "), Maybe("what? "))
print Maybe(foo)(Maybe("hello! "), Nothing)

8<8<8<8<8<8<8<

I haven't tested it very thoroughly, so it's quite possible there are
lots of bugs in it, but it is only intended as a demo.

As Gabriel Genellina pointed out, the search for special methods is done
in the type, so we have to put our own versions there, during type
creation in the metaclass' __new__ method. The above code does this for
all methods of the wrapped object's type, not just special ones, and
"lifts" them to expect Maybe objects instead of "normal" objects. They
also wrap their return values into Maybe objects.

Maybe is an algebraic data type. The call Maybe(some_value) returns
either Nothing, if some_value happens to be Nothing, or else an object
of type Just that wraps some_value. More precisely, there is not one
type Just, but as many as types of Just-wrapped objects (Just,
Just, ...). Just is therefore a kind of parameterized type. It's
similar to inheriting from a C++ template parameter type:

template 
class MyType : public T {...}

but not quite, since in C++ the inherited member functions' signatures
are unchanged, whereas in the above code "inherited" methods are changed
to expect and return Maybe objects.

Some things don't work, though, e.g. slicing. But this could be
imp

Web development with Python 3.1

2009-10-25 Thread Alan Harris-Reid


I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of 
you shouting "don't - start with 2.6"), but as far as I can see, none of 
the popular python-to-web frameworks (Django, CherryPy, web.py, etc.) 
are Python3 compatible yet.


So, what can I use to start my web programming experience using 3.1?

Any help would be appreciated.

Alan

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


Python GUI

2009-10-25 Thread Ronn Ross
I need to create a gui for python. I'm looking for something that is easy to
learn and cross platform. Any suggestions? If you have any good tutorials
please send along. Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-25 Thread Paul Rubin
Alan Harris-Reid  writes:
> I am very much new to Python, and one of my first projects is a simple
> data-based website. I am starting with Python 3.1 (I can hear many of
> you shouting "don't - start with 2.6"), but as far as I can see, none
> of the popular python-to-web frameworks (Django, CherryPy, web.py,
> etc.) are Python3 compatible yet.
> 
> So, what can I use to start my web programming experience using 3.1?

Does it occur to you that the unavailability of those frameworks is
part of the REASON they say to use 2.x?  Have you answered your own
question?

Anyway, for simple web programming, frameworks are not worth the
hassle.  Just use the cgi module.

If you want to use a framework, well, you are the one who decided to
zoom off into the 3.1 wilderness before the framework developers got
there.  If you're an experienced programmer in other languages and
you're determined to use a framework, maybe a worthwhile Python
learning project would be to help port your favorite framework to 3.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-25 Thread exarkun

On 25 Oct, 11:52 pm, [email protected] wrote:


I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of 
you shouting "don't - start with 2.6"), but as far as I can see, none 
of the popular python-to-web frameworks (Django, CherryPy, web.py, 
etc.) are Python3 compatible yet.


So, what can I use to start my web programming experience using 3.1?

Any help would be appreciated.


don't - start with 2.6

Alan

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

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


Re: Web development with Python 3.1

2009-10-25 Thread Brendon Wickham
>
> Anyway, for simple web programming, frameworks are not worth the
> hassle.  Just use the cgi module.
>
>
I can vouch for what Paul says. I started in Python 3 years ago, and I did
so with a web application (still working on it!). I'm using the cgi
approach, and it certainly teaches you the concepts. I fail to see how
starting with a framework is a good idea if you don't know how the
frameworks work (or what they're actually doing). It would be a bit like
doing a web page in Dreamw***er and thinking you understand HTML/CSS.

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


Re: Python GUI

2009-10-25 Thread Philip Semanchuk


On Oct 25, 2009, at 8:39 PM, Ronn Ross wrote:

I need to create a gui for python. I'm looking for something that is  
easy to
learn and cross platform. Any suggestions? If you have any good  
tutorials

please send along. Thanks in advance.


wxPython (which wraps wxWidgets) is popular and IMO reasonably well  
laid out. I hear great things about PyQt (which wraps QT) but I  
haven't used it. PySide is a new wrapper for QT that has generated a  
lot of excitement but is still its infancy, I think.



HTH
Philip

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


Re: Python GUI

2009-10-25 Thread Ronn Ross
Philip,

PySide looks nice and you are right it is still very young. I'm still going
to give it a try. Thanks for your help.

On Sun, Oct 25, 2009 at 9:41 PM, Philip Semanchuk wrote:

>
> On Oct 25, 2009, at 8:39 PM, Ronn Ross wrote:
>
>  I need to create a gui for python. I'm looking for something that is easy
>> to
>> learn and cross platform. Any suggestions? If you have any good tutorials
>> please send along. Thanks in advance.
>>
>
> wxPython (which wraps wxWidgets) is popular and IMO reasonably well laid
> out. I hear great things about PyQt (which wraps QT) but I haven't used it.
> PySide is a new wrapper for QT that has generated a lot of excitement but is
> still its infancy, I think.
>
>
> HTH
> Philip
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python GUI

2009-10-25 Thread geremy condra
On Sun, Oct 25, 2009 at 10:03 PM, Ronn Ross  wrote:
> Philip,
>
> PySide looks nice and you are right it is still very young. I'm still going
> to give it a try. Thanks for your help.
>
> On Sun, Oct 25, 2009 at 9:41 PM, Philip Semanchuk 
> wrote:
>>
>> On Oct 25, 2009, at 8:39 PM, Ronn Ross wrote:
>>
>>> I need to create a gui for python. I'm looking for something that is easy
>>> to
>>> learn and cross platform. Any suggestions? If you have any good tutorials
>>> please send along. Thanks in advance.
>>
>> wxPython (which wraps wxWidgets) is popular and IMO reasonably well laid
>> out. I hear great things about PyQt (which wraps QT) but I haven't used it.
>> PySide is a new wrapper for QT that has generated a lot of excitement but is
>> still its infancy, I think.
>>
>>
>> HTH
>> Philip

Was surprised to see that PyGUI didn't make it onto the list. Pretty nice,
IMHO- and I say that as somebody who prefers Qt in C++.

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


Re: Python GUI

2009-10-25 Thread Grant Edwards
On 2009-10-26, Philip Semanchuk  wrote:
>
> On Oct 25, 2009, at 8:39 PM, Ronn Ross wrote:
>
>> I need to create a gui for python. I'm looking for something that is  
>> easy to
>> learn and cross platform. Any suggestions? If you have any good  
>> tutorials
>> please send along. Thanks in advance.
>
> wxPython (which wraps wxWidgets) is popular and IMO reasonably well  
> laid out.

I wouldn't call wxPython easy to learn.  (It is, however, what
I use when I need a cross-platform GUI.) IMO, Tkinter is much
easier to learn. But, it doesn't use native widgets, so Tkinter
apps look like Tkinter apps rather than like other native apps.

> I hear great things about PyQt (which wraps QT) but I haven't
> used it. PySide is a new wrapper for QT that has generated a 
> lot of excitement but is still its infancy, I think.

I've always intended to look into pyFLTK, but have never had
time to do more than a simple "hello world" program.

-- 
Grant


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


Re: Python 2.6 Deprecation Warnings with __new__ — Can someone explain why?

2009-10-25 Thread rh0dium
Carl,

First off - Thanks your post was exactly the kind of informative
example driven learnings that help — Thanks!!



On Oct 22, 9:05 pm, Carl Banks  wrote:

>
> Before we get into object semantics, I'm not sure why you'd need to
> override __new__ for Borg pattern, unless they're working around some
> edge cases or something.
> For that matter you shouldn't need args and kwargs either, you know
> what the arguments to your function are.

Good point — admitadly I blindly followed Alex M's advice.  I am still
working my way through this.  Point taken.

>
> This should suffice for you:
>
> class Borg(object):
>     __shared_state = {}
>     def __init__(self, noSend=False,reportLevel=30,
>                  reportMethods="BaseReport",
>                  contacts=None):
>         self.__dict__ = self.__shared_state
>         self.noSend = noSend
>         self.reportLevel = reportLevel
>         self.reportMethods = reportMethods
>         self.contacts = contacts
>
> This (as well as your class) will update the shared state for all Borg
> objects whenever you instantiate a new Borg object.  That might be
> what you want, but be aware.


Now the real question I have on this is scalability.  The real
advantage to using *args and **kwargs is that down the road (through
inheritance/polymorphism) I may not know what I'm being given (isn't
that the essence of duck-typing). My long standing belief is that by
using *args and **kwargs I plan for future additions with minimal
changes to my code.  So doesn't restricting this just defeat the
purpose?

>
> > In my case the args that it dumps them into a black hold is simply not
> > true.
>
> Actually it is.
>
> > I want an unknown set of args and kwargs to simply be forwarded
> > onto init.  So what's the problem with this??
>
> The problem is that __new__ doesn't forward the arguments to
> __init__.  Look at what happens when you call this class:
>
> class X(object):
>     def __new__(cls,*args,**kwargs):
>         return object.__new__(cls)
>     def __init__(self,*args,**kwargs):
>         print args, kwargs
>
> X(1,2,q=3,g=4)
>
> Note that *args and **kwargs are not passed to object.__new__, but
> nevertheless __init__ is still called with them.
>
> What's actually happens is that the type object's __call__ method
> passes the same arguments to both __new__ and __init__.
>
> The fact is, object.__new__ does nothing at all with the args and
> kwargs arguments, it just ignores them.  So, when calling
> object.__new__, don't pass them to it.

So what is the point of using __new__?  After a bit of reading
http://docs.python.org/reference/datamodel.html 3.4.1 and I think I
understand.  More to the point you made above.  The whole necessity of
__new__ above makes most of this moot ;)


Once again thanks Carl for your great response!!

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


Re: python web service or Apache?

2009-10-25 Thread Simon Forman
On Sun, Oct 25, 2009 at 4:47 PM, Peng Yu  wrote:
> Although, python can be used to provide web service. The following
> webpage also mentioned, "Apache the best and most widely used web
> server on the Internet today, check it out. If you want to run your
> own web server this is the one to get, you can get binaries for both
> Windows and Unix. You can download the entire sourcecode if you want
> to check how it was made." Therefore, it would be better to use Apache
> rather than python to provide web service, right?
>
> http://fragments.turtlemeat.com/pythonwebserver.php


Both "best" and "better" (that website and you, respectively) omit
mention of the criteria used for the evaluation.

To determine what is "best" you must first answer "for what?"


(Also, it is reasonable to use /both/ apache and python together, with
mod_python or mod_wsgi, etc...)


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


Re: Python 3.1.1 bytes decode with replace bug

2009-10-25 Thread Mark Tolonen


"Dave Angel"  wrote in message 
news:[email protected]...

Joe wrote:

For the reason BK explained, the important difference is that I ran in
the IDLE shell, which handles screen printing of unicode better ;-)



Something still does not seem right here to me.

In the example above the bytes were decoded to 'UTF-8' with the


*nope*  you're decoding FROM utf-8 to unicode.

replace option so any characters that were not UTF-8 were replaced and
the resulting string is '\ufffdabc' as BK explained.  I understand
that the replace worked.

Now consider this:

Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.


s = '\ufffdabc'
print(s)


Traceback (most recent call last):
  File "", line 1, in 
  File "p:\SW64\Python.3.1.1\lib\encodings\cp437.py", line 19, in
encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in
position
0: character maps to 


import sys
sys.getdefaultencoding()


'utf-8'

This too fails for the exact same reason (and doesn't invole decode).

In the original example I decoded to UTF-8 and in this example the
default encoding is UTF-8 so why is cp437 being used?

Thanks in advance for your assistance!




Benjamin had it right, but you still don't understand what he said.

The problem in your original example, and in the current one, is not in 
decode(), but in encode(), which is implicitly called by print(), when 
needed to convert from Unicode to some byte format of the console.  Take 
your original example:



 b'\x80abc'.decode('utf-8', 'replace')



The decode() is explicit, and converts *FROM* utf8 string to a unicode 
one.  But since you're running in a debugger, there's an implicit print, 
which is converting unicode into whatever your default console encoding 
is.  That calls encode() (or one of its variants,  charmap_encode(), on 
the unicode string.  There is no relationship between the two steps.


In your current example, you're explicitly doing the print(), but still 
have the same implicit encoding to cp437, which gets the equivalent error. 
That's the encoding that your Python 3.x is choosing for the stdout 
console, based on country-specific Windows settings.  In the US, that 
implicit encoding is ASCII.  I don't know how to override it generically, 
but I know it's possible to replace stdout with a wrapper that does your 
preferred encoding.  You probably want to keep cp437, but change the error 
handling to ignore.  Or if this is a one-time problem, I suspect you could 
do the encoding manually, to a byte array, then print that.


You can also replace the Unicode replacement character U+FFFD with a valid 
cp437 character before displaying it:



b'\x80abc'.decode('utf8','replace').replace('\ufffd','?')

'?abc'

-Mark 



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


Re: How to modify local variables from internal functions?

2009-10-25 Thread Steven D'Aprano
On Sat, 24 Oct 2009 00:19:12 +, kj wrote:

> I like Python a lot, and in fact I'm doing most of my scripting in
> Python these days, but one thing that I absolutely *DETEST*
> about Python is that it does allow an internal function to modify
> variables in the enclosing local scope.

You can't rebind names in the enclosing scope (not without the nonlocal 
keyword, which I believe is introduced in Python 3.0):


>>> def func():
... x = 1
... def inner():
... x = 2
... inner()
... print x
...
>>> func()
1


However, naturally you can call methods on objects bound in the outer 
scope. It would be rather inconvenient if you couldn't access them from 
inner functions, but that's how Python was prior to the introduction of 
nested scopes in 2.1.


Given this code:

def f():
L = [1, 2, 3]
def inner():
return L.index(1)
return inner()

f()


This is what you get in Python 1.5:

Traceback (innermost last):
  File "", line 1, in ?
  File "", line 5, in f
  File "", line 4, in inner
NameError: L


while in current versions of Python, you get 0.

Of course, once you allow inner functions to call methods on objects in 
the outer scope, you allow methods which mutate the object:

>>> def f():
... L = []
... def inner():
... L.append(None)
... inner()
... print L
...
>>> f()
[None]

What other behaviour would you expect?



> This willful hobbling of
> internal functions seems to me so perverse and unnecessary that it
> delayed my adoption of Python by about a decade.  Just thinking about it
> brings me to the brink of blowing a gasket...  I must go for a walk...

I think you don't understand the object and assignment model of Python if 
you think this is "hobbling of internal functions".


> Anyway, I recently wanted to write a internal helper function that
> updates an internal list and returns True if, after this update, the
> list is empty, and once more I bumped against this hated "feature". 
> What I wanted to write, if Python did what I wanted it to, was this:
[...]
> But, of course, the above does not work in Python, because the jobs
> variable local to spam does not get updated by check_finished. G!

Okay, now I'm completely confused. You "DETEST" (shouting was yours) that 
Python objects can be modified by inner functions, and yet here you are 
writing a function which relies on that -- and gets it wrong, because 
you're trying to rebind a name rather than modify an object.

Others have suggested the nonlocal keyword in 3.x. Here's another 
solution:


def spam():
jobs = look_for_more_jobs()
if not jobs:
return
process1(jobs)
jobs = look_for_more_jobs()
if not jobs:
return
process2(jobs)
jobs = look_for_more_jobs()
if not jobs:
return
process3(jobs)



which immediately suggests refactoring:


def spam():
for process in (process1, process2, process3):
jobs = look_for_more_jobs()
if not jobs:
return
process(jobs)



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


Re: How to modify local variables from internal functions?

2009-10-25 Thread Steven D'Aprano
On Sat, 24 Oct 2009 00:19:12 +, kj wrote:

> I like Python a lot, and in fact I'm doing most of my scripting in
> Python these days, but one thing that I absolutely *DETEST*
> about Python is that it does allow an internal function to modify
> variables in the enclosing local scope.

You can't rebind names in the enclosing scope (not without the nonlocal 
keyword, which I believe is introduced in Python 3.0):


>>> def func():
... x = 1
... def inner():
... x = 2
... inner()
... print x
...
>>> func()
1


However, naturally you can call methods on objects bound in the outer 
scope. It would be rather inconvenient if you couldn't access them from 
inner functions, but that's how Python was prior to the introduction of 
nested scopes in 2.1.


Given this code:

def f():
L = [1, 2, 3]
def inner():
return L.index(1)
return inner()

f()


This is what you get in Python 1.5:

Traceback (innermost last):
  File "", line 1, in ?
  File "", line 5, in f
  File "", line 4, in inner
NameError: L


while in current versions of Python, you get 0.

Of course, once you allow inner functions to call methods on objects in 
the outer scope, you allow methods which mutate the object:

>>> def f():
... L = []
... def inner():
... L.append(None)
... inner()
... print L
...
>>> f()
[None]

What other behaviour would you expect?



> This willful hobbling of
> internal functions seems to me so perverse and unnecessary that it
> delayed my adoption of Python by about a decade.  Just thinking about it
> brings me to the brink of blowing a gasket...  I must go for a walk...

I think you don't understand the object and assignment model of Python if 
you think this is "hobbling of internal functions".


> Anyway, I recently wanted to write a internal helper function that
> updates an internal list and returns True if, after this update, the
> list is empty, and once more I bumped against this hated "feature". 
> What I wanted to write, if Python did what I wanted it to, was this:
[...]
> But, of course, the above does not work in Python, because the jobs
> variable local to spam does not get updated by check_finished. G!

Okay, now I'm completely confused. You "DETEST" (shouting was yours) that 
Python objects can be modified by inner functions, and yet here you are 
writing a function which relies on that -- and gets it wrong, because 
you're trying to rebind a name rather than modify an object.

Others have suggested the nonlocal keyword in 3.x. Here's another 
solution:


def spam():
jobs = look_for_more_jobs()
if not jobs:
return
process1(jobs)
jobs = look_for_more_jobs()
if not jobs:
return
process2(jobs)
jobs = look_for_more_jobs()
if not jobs:
return
process3(jobs)



which immediately suggests refactoring:


def spam():
for process in (process1, process2, process3):
jobs = look_for_more_jobs()
if not jobs:
return
process(jobs)





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


RE: Python GUI

2009-10-25 Thread Dylan Palmboom
 PyQt is what we use at work and it is excellent and easy to learn too! I
definitely recommend it.


-Original Message-
From: Philip Semanchuk [mailto:[email protected]] 
Sent: 26 October 2009 03:42 AM
To: Python-list (General)
Subject: Re: Python GUI


On Oct 25, 2009, at 8:39 PM, Ronn Ross wrote:

> I need to create a gui for python. I'm looking for something that is 
> easy to learn and cross platform. Any suggestions? If you have any 
> good tutorials please send along. Thanks in advance.

wxPython (which wraps wxWidgets) is popular and IMO reasonably well laid
out. I hear great things about PyQt (which wraps QT) but I haven't used it.
PySide is a new wrapper for QT that has generated a lot of excitement but is
still its infancy, I think.


HTH
Philip



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


Re: Python 2.6 Deprecation Warnings with __new__ — Can someone explain why?

2009-10-25 Thread Carl Banks
On Oct 25, 9:04 pm, rh0dium  wrote:
> On Oct 22, 9:05 pm, Carl Banks  wrote:
> > This should suffice for you:
>
> > class Borg(object):
> >     __shared_state = {}
> >     def __init__(self, noSend=False,reportLevel=30,
> >                  reportMethods="BaseReport",
> >                  contacts=None):
> >         self.__dict__ = self.__shared_state
> >         self.noSend = noSend
> >         self.reportLevel = reportLevel
> >         self.reportMethods = reportMethods
> >         self.contacts = contacts
>
> > This (as well as your class) will update the shared state for all Borg
> > objects whenever you instantiate a new Borg object.  That might be
> > what you want, but be aware.
>
> Now the real question I have on this is scalability.  The real
> advantage to using *args and **kwargs is that down the road (through
> inheritance/polymorphism) I may not know what I'm being given (isn't
> that the essence of duck-typing).

No, duck-typing means you don't necessarily know the types of
arguments you're getting.  Not knowing the number, pattern, or usage
of the arguments you're getting is something else.

> My long standing belief is that by
> using *args and **kwargs I plan for future additions with minimal
> changes to my code.  So doesn't restricting this just defeat the
> purpose?

If that's your intended purpose down the road, feel free to do it.
(Not sure why you would do that with a singleton, but that's your
business.)

Personally, I wouldn't recommend replacing regular arguments with
*args and **kwargs unless there was a specific reason to believe that
this class would be used in a heirarchy where it's expected to pass on
arguments it doesn't know about.  If it just "might someday" be used
that way, I'd say it's a lot of unnecessary caution.

One place I do recommend using *args and **kwargs is with mixin
classes, because mixins usually are required to pass along unknown
arguments, not just "might be someday".


> > The fact is, object.__new__ does nothing at all with the args and
> > kwargs arguments, it just ignores them.  So, when calling
> > object.__new__, don't pass them to it.
>
> So what is the point of using __new__?

It's mostly for types written in C, or for subclassing types written
in C.  Advanced programmers can take advantage of it to do some
interesting things, but most of the time __init__ suffices.


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