comp.lang.python - 26 new messages in 11 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* GIL state during import - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b9ba52627893a79d?hl=en
* ANN: obfuscate 0.2.2b - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ba5c54c167aea1e5?hl=en
* listing existing windows services with python - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a8c444a258aabc30?hl=en
* How to efficiently extract information from structured text file - 3
messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/bc8840f8a254056b?hl=en
* Parsing for email addresses - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/3bb4a0aef7be5837?hl=en
* Interesting talk on Python vs. Ruby and how he would like Python to have
just a bit more syntactic flexibility. - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/9a88c79d4043ba30?hl=en
* Shipping Executables - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/297a2754b1ad0538?hl=en
* Download unnamed web image? - 6 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/bbc7a4a86e42d7e9?hl=en
* Hubris connects Ruby to Haskell, will there be such a connection between
Python and Haskell? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/5b5a0c768c788353?hl=en
* Is there a simple way to find the list index to the max value? - 1 messages,
1 author
http://groups.google.com/group/comp.lang.python/t/b8456fe748df61e2?hl=en
* The future of "frozen" types as the number of CPU cores increases - 4
messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/7ef75c20d1be370d?hl=en
==============================================================================
TOPIC: GIL state during import
http://groups.google.com/group/comp.lang.python/t/b9ba52627893a79d?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 16 2010 3:01 pm
From: Terry Reedy
On 2/16/2010 4:37 PM, Doron Tal wrote:
> Is the GIL released during import statement execution when accessing the
> file?
> If not, is it a bug?
> If it is not a bug, or it is here to stay for any other reason, I think
> it should be mentioned in the documentation.
The CPython GIL is a CPython implementation artifact and should not be
mentioned in the language docs (and is not, as far as I know). Were you
thinking of something else? And why this specific feature of its
behavior, whatever it is.
tjr
==============================================================================
TOPIC: ANN: obfuscate 0.2.2b
http://groups.google.com/group/comp.lang.python/t/ba5c54c167aea1e5?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 16 2010 3:19 pm
From: Steven D'Aprano
I am pleased to announce the beta release of obfuscate 0.2.2b.
http://pypi.python.org/pypi/obfuscate/
The beta release does not contain any new functionality from the previous
version, but includes bug fixes and many new tests.
obfuscate is a pure-Python module providing classical encryption
algorithms suitable for obfuscating and unobfuscating text.
obfuscate includes the following ciphers:
- Caesar, rot13, rot5, rot18, rot47
- atbash
- Playfair, Playfair6 and Playfair16
- Railfence (encryption only)
- Keyword
- Affine
- Vigenere
- frob (xor)
and others.
DISCLAIMER: obfuscate is not cryptographically strong, and should not be
used where high security is required. (The ciphers provided in obfuscate
may have been state of the art centuries ago, but should not be used where
strong encryption is required.
obfuscate is released under the MIT licence.
Requires Python 2.5 or 2.6.
==============================================================================
TOPIC: listing existing windows services with python
http://groups.google.com/group/comp.lang.python/t/a8c444a258aabc30?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 16 2010 3:34 pm
From: David Bolen
alex23 <wuwei23@gmail.com> writes:
> News123 <news...@free.fr> wrote:
>> What is the best way with python to get a list of all windows services.
>>
>> As a start I would be glad to receive only the service names.
>>
>> However it would be nicer if I could get all the properties of a service
>> as well.
>
> I highly recommend Tim Golden's fantastic WMI module[1].
Another alternative is the win32service module from the pywin32
package (which IMO you'll almost certainly want available when doing
any significant Windows-specific operations) which wraps the native
win32 libraries for enumerating, querying and controlling services.
A simple loop could use EnumServicesStatus to iterate through the
services, OpenService with the SERVICE_QUERY_CONFIG flag to get a
handle to each service, and then QueryServiceConfig to retrieve
configuration information.
Since pywin32 is a relatively thin wrapper over the win32 libraries,
pure MSDN documentation can be used for help with the calls, augmented
by any Python-related information contained in the pywin32
documentation.
-- David
==============================================================================
TOPIC: How to efficiently extract information from structured text file
http://groups.google.com/group/comp.lang.python/t/bc8840f8a254056b?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Feb 16 2010 3:48 pm
From: Imaginationworks
Hi,
I am trying to read object information from a text file (approx.
30,000 lines) with the following format, each line corresponds to a
line in the text file. Currently, the whole file was read into a
string list using readlines(), then use for loop to search the "= {"
and "};" to determine the Object, SubObject,and SubSubObject. My
questions are
1) Is there any efficient method that I can search the whole string
list to find the location of the tokens(such as '= {' or '};'
2) Is there any efficient ways to extract the object information you
may suggest?
Thanks,
- Jeremy
===== Structured text file =================
Object1 = {
...
SubObject1 = {
....
SubSubObject1 = {
...
};
};
SubObject2 = {
....
SubSubObject21 = {
...
};
};
SubObjectN = {
....
SubSubObjectN = {
...
};
};
};
== 2 of 3 ==
Date: Tues, Feb 16 2010 4:29 pm
From: "Rhodri James"
On Tue, 16 Feb 2010 23:48:17 -0000, Imaginationworks <xiajunyi@gmail.com>
wrote:
> Hi,
>
> I am trying to read object information from a text file (approx.
> 30,000 lines) with the following format, each line corresponds to a
> line in the text file. Currently, the whole file was read into a
> string list using readlines(), then use for loop to search the "= {"
> and "};" to determine the Object, SubObject,and SubSubObject. My
> questions are
>
> 1) Is there any efficient method that I can search the whole string
> list to find the location of the tokens(such as '= {' or '};'
The usual idiom is to process a line at a time, which avoids the memory
overhead of reading the entire file in, creating the list, and so on.
Assuming your input file is laid out as neatly as you said, that's
straightforward to do:
for line in myfile:
if "= {" in line:
start_a_new_object(line)
elif "};" in line:
end_current_object(line)
else:
add_stuff_to_current_object(line)
You probably want more robust tests than I used there, but that depends on
how well-defined your input file is. If it can be edited by hand, you'll
need to be more defensive!
> 2) Is there any efficient ways to extract the object information you
> may suggest?
That depends on what you mean by "extract the object information". If you
mean "get the object name", just split the line at the "=" and strip off
the whitespace you don't want. If you mean "track how objects are
connected to one another, have each object keep a list of its immediate
sub-objects (which will have lists of their immediate sub-objects, and so
on); it's fairly easy to keep track of which objects are current using a
list as a stack. If you mean something else, sorry but my crystal ball is
cloudy tonight.
--
Rhodri James *-* Wildebeeste Herder to the Masses
== 3 of 3 ==
Date: Tues, Feb 16 2010 5:14 pm
From: Gary Herron
Imaginationworks wrote:
> Hi,
>
> I am trying to read object information from a text file (approx.
> 30,000 lines) with the following format, each line corresponds to a
> line in the text file. Currently, the whole file was read into a
> string list using readlines(), then use for loop to search the "= {"
> and "};" to determine the Object, SubObject,and SubSubObject. My
> questions are
>
> 1) Is there any efficient method that I can search the whole string
> list to find the location of the tokens(such as '= {' or '};'
>
Yes. Read the *whole* file into a single string using file.read()
method, and then search through the string using string methods (for
simple things) or use re, the regular expression module, (for more
complex searches).
Note: There is a point where a file becomes large enough that reading
the whole file into memory at once (either as a single string or as a
list of strings) is foolish. However, 30,000 lines doesn't push that
boundary.
> 2) Is there any efficient ways to extract the object information you
> may suggest?
>
Again, the re module has nice ways to find a pattern, and return parse
out pieces of it. Building a good regular expression takes time,
experience, and a bit of black magic... To do so for this case, we
might need more knowledge of your format. Also regular expressions have
their limits. For instance, if the sub objects can nest to any level,
then in fact, regular expressions alone can't solve the whole problem,
and you'll need a more robust parser.
> Thanks,
>
> - Jeremy
>
>
>
> ===== Structured text file =================
> Object1 = {
>
> ...
>
> SubObject1 = {
> ....
>
> SubSubObject1 = {
> ...
> };
> };
>
> SubObject2 = {
> ....
>
> SubSubObject21 = {
> ...
> };
> };
>
> SubObjectN = {
> ....
>
> SubSubObjectN = {
> ...
> };
> };
> };
>
==============================================================================
TOPIC: Parsing for email addresses
http://groups.google.com/group/comp.lang.python/t/3bb4a0aef7be5837?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 16 2010 4:07 pm
From: galileo228
Tim -
Thanks for this. I actually did intend to have to sift through other
junk in the file, but then figured I could just cut and paste emails
directly from the 'to' field, thus making life easier.
Also, in this particular instance, the domain names were the same, and
thus I was able to figure out my solution, but I do need to know how
to handle the same situation when the domain names are different, so
your response was most helpful.
Apologies for leaving out some details.
Matt
On Feb 16, 3:15 pm, Tim Chase <python.l...@tim.thechases.com> wrote:
> galileo228 wrote:
> > [code]
> > fileHandle = open('/Users/Matt/Documents/python/results.txt','r')
> > names = fileHandle.readlines()
> > [/code]
>
> > Now, the 'names' list has values looking like this: ['aa...@domain.com
> > \n', 'bb...@domain.com\n', etc]. So I ran the following code:
>
> > [code]
> > for x in names:
> > st_list.append(x.replace('...@domain.com\n',''))
> > [/code]
>
> > And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc].
>
> > Obviously this only worked because all of the domain names were the
> > same. If they were not then based on your comments and my own
> > research, I would've had to use regex and the split(), which looked
> > massively complicated to learn.
>
> The complexities stemmed from several factors that, with more
> details, could have made the solutions less daunting:
>
> (a) you mentioned "finding" the email addresses -- this makes
> it sound like there's other junk in the file that has to be
> sifted through to find "things that look like an email address".
> If the sole content of the file is lines containing only email
> addresses, then "find the email address" is a bit like [1]
>
> (b) you omitted the detail that the domains are all the same.
> Even if they're not the same, (a) reduces the problem to a much
> easier task:
>
> s = set()
> for line in file('results.txt'):
> s.add(line.rsplit('@', 1)[0].lower())
> print s
>
> If it was previously a CSV or tab-delimited file, Python offers
> batteries-included processing to make it easy:
>
> import csv
> f = file('results.txt', 'rb')
> r = csv.DictReader(f) # CSV
> # r = csv.DictReader(f, delimiter='\t') # tab delim
> s = set()
> for row in r:
> s.add(row['Email'].lower())
> f.close()
>
> or even
>
> f = file(...)
> r = csv.DictReader(...)
> s = set(row['Email'].lower() for row in r)
> f.close()
>
> Hope this gives you more ideas to work with.
>
> -tkc
>
> [1]http://jacksmix.files.wordpress.com/2007/05/findx.jpg
==============================================================================
TOPIC: Interesting talk on Python vs. Ruby and how he would like Python to
have just a bit more syntactic flexibility.
http://groups.google.com/group/comp.lang.python/t/9a88c79d4043ba30?hl=en
==============================================================================
== 1 of 3 ==
Date: Tues, Feb 16 2010 4:19 pm
From: Jonathan Gardner
On Feb 16, 11:41 am, Andrej Mitrovic <andrej.mitrov...@gmail.com>
wrote:
> On Feb 16, 7:38 pm, Casey Hawthorne <caseyhHAMMER_T...@istar.ca>
> wrote:
>
> > Interesting talk on Python vs. Ruby and how he would like Python to
> > have just a bit more syntactic flexibility.
>
> >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de...
> > --
> > Regards,
> > Casey
>
> Gary's friend Geoffrey Grosenbach says in his blog post (which Gary
> linked to): "Python has no comparable equivalent to Ruby's do end
> block. Python lambdas are limited to one line and can't contain
> statements (for, if, def, etc.). Which leaves me wondering, what's the
> point?"
>
> I'm sorry, lambda's do support if's and for's. Also, lambda's are
> expressions, not statements, but you can pass them around, keep them
> in a dictionary if you want to. And if you need more than one line of
> statements, for crying out loud use a def? And who needs those "do-
> end" blocks anyway, trying to turn Python into Pascal?
I used to think anonymous functions (AKA blocks, etc...) would be a
nice feature for Python.
Then I looked at a stack trace from a different programming language
with lots of anonymous functions. (I believe it was perl.)
I became enlightened.
== 2 of 3 ==
Date: Tues, Feb 16 2010 4:56 pm
From: aahz@pythoncraft.com (Aahz)
In article <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com>,
Jonathan Gardner <jgardner@jonathangardner.net> wrote:
>
>I used to think anonymous functions (AKA blocks, etc...) would be a
>nice feature for Python.
>
>Then I looked at a stack trace from a different programming language
>with lots of anonymous functions. (I believe it was perl.)
>
>I became enlightened.
+1 QOTW
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)"
== 3 of 3 ==
Date: Tues, Feb 16 2010 7:04 pm
From: David Cournapeau
On Wed, Feb 17, 2010 at 4:41 AM, Andrej Mitrovic
<andrej.mitrovich@gmail.com> wrote:
>
> Gary's friend Geoffrey Grosenbach says in his blog post (which Gary
> linked to): "Python has no comparable equivalent to Ruby's do end
> block. Python lambdas are limited to one line and can't contain
> statements (for, if, def, etc.). Which leaves me wondering, what's the
> point?"
>
> I'm sorry, lambda's do support if's and for's. Also, lambda's are
> expressions, not statements, but you can pass them around, keep them
> in a dictionary if you want to. And if you need more than one line of
> statements, for crying out loud use a def?
I think that's a bit of a strawman: the point made by the OP is that
it enables writing simple DSL easier, and the ruby's community seems
to value this. They are not advocating using anonymous functions where
"normal" functions would do.
cheers,
David
==============================================================================
TOPIC: Shipping Executables
http://groups.google.com/group/comp.lang.python/t/297a2754b1ad0538?hl=en
==============================================================================
== 1 of 4 ==
Date: Tues, Feb 16 2010 4:22 pm
From: Philip Semanchuk
On Feb 16, 2010, at 4:41 PM, rodmc wrote:
> Hi,
>
> I have been merrily programming away in Python now for a few years and
> have a couple of applications I would like to possibly publish at some
> point - with the exception of certain libraries they are more or less
> 100% Python. However I have read elsewhere online that Python due to
> it's architecture is not so good for this, especially as it is easier
> for people to hack into the code. Also where software requires some
> security aspects I guess it would also not be much use, is this
> correct?
Hi Rod,
The user's ability to hack into the code is usually considered one of
the strengths of Python & open source software in general. Since most
Python software that's distributed is open source, you're doing
something different than most. It'd help if you explain how you want
your software to differ from a typical open source distribution. Do
you not want people to change the code? Are you worried about your
code & ideas being stolen?
bye
Philip
== 2 of 4 ==
Date: Tues, Feb 16 2010 6:11 pm
From: Steven D'Aprano
On Tue, 16 Feb 2010 13:41:21 -0800, rodmc wrote:
> Hi,
>
> I have been merrily programming away in Python now for a few years and
> have a couple of applications I would like to possibly publish at some
> point - with the exception of certain libraries they are more or less
> 100% Python. However I have read elsewhere online that Python due to
> it's architecture is not so good for this, especially as it is easier
> for people to hack into the code.
Looks like you are looking to apply the philosophy "No user serviceable
parts inside".
> Also where software requires some
> security aspects I guess it would also not be much use, is this correct?
Absolutely 100% wrong. It is an fundamental principle of security that
you must not assume that the enemy is ignorant of your procedures.
"Security by obscurity" is not security at all.
See, for example:
http://en.wikipedia.org/wiki/Kerckhoffs'_Principle
If you are trusting that your software will be secure because people
cannot read the source code, you have already failed. Hackers break into
computer systems without the source code as a matter of course: allowing
the source to be available generally makes so little difference as to be
no difference. Worse, keeping the source code secret *as a security
measure* lulls people into a false sense of security, letting them use
weak security confident that since nobody knows how weak it is, it will
be strong. That's not how it works.
If you have other reasons for wanting to keep the source code secret,
that's one thing. But doing it because it is more secure is foolish:
software simply isn't more secure when supplied as a binary instead of
source code.
> Anyway I would appreciate any views or tips that people have?
Don't worry about it. If your application is secure, it will be secure
even if everybody knows how it works. If it's not secure, then the bad
guys will learn how it works even without the source code.
--
Steven
== 3 of 4 ==
Date: Tues, Feb 16 2010 11:00 pm
From: geremy condra
On Wed, Feb 17, 2010 at 1:10 AM, Banibrata Dutta
<banibrata.dutta@gmail.com> wrote:
>
>
> On Wed, Feb 17, 2010 at 7:41 AM, Steven D'Aprano
> <steven@remove.this.cybersource.com.au> wrote:
>>
>> > security aspects I guess it would also not be much use, is this correct?
>> Absolutely 100% wrong. It is an fundamental principle of security that
>> you must not assume that the enemy is ignorant of your procedures.
>> "Security by obscurity" is not security at all.
>>
>> See, for example:
>>
>> http://en.wikipedia.org/wiki/Kerckhoffs'_Principle
>>
> I believe, the use of work 'security' wasn't the best choice to describe the
> need, if I understand the original poster's intentions. The intentions of
> original poster were "intellectual property protection",
Which has little to do with the language in question.
> where-in they have
> indeed created something worth stealing, and would like to put it under
> lock-n-key. For that purpose, I do not think Python is the right choice.
Why?
> BTW for people who are non-believers in something being worth stealing
> needing protection, need to read about the Skype client.
Most of the people I know who were interested in REing skype were
a lot more interested in either interoperating with the protocol or ensuring
that skype wasn't deliberately including malware or a backdoor. In any
even I don't see this having anything to do with Python.
Geremy Condra
== 4 of 4 ==
Date: Tues, Feb 16 2010 11:36 pm
From: Steven D'Aprano
On Wed, 17 Feb 2010 02:00:59 -0500, geremy condra quoted Banibrata Dutta
<banibrata.dutta@gmail.com>:
>> BTW for people who are non-believers in something being worth stealing
>> needing protection, need to read about the Skype client.
Pardon me for breaking threading, but the original post has not come
through to my provider, only the reply from Geremy.
Many things are worth stealing and therefore need protection.
In any case, reverse engineering software is not theft. And even if it
were, keeping the source code secret is no barrier to a competent,
determined attacker or investigator. Skype is a good example: despite the
lack of source code and the secret protocol, analysts were able to
discover that TOM-Skype sends personally identifiable information,
encryption keys and private messages back to central servers.
In my personal opinion, releasing closed source software is prima facie
evidence that the software is or does something bad: leaking personal
information, infringing somebody else's copyright or patent, or just
being badly written. I'm not saying that every piece of closed source
software is like that, but when you hide the source, the burden of proof
is on you to prove that you're not hiding something unpleasant.
--
Steven
==============================================================================
TOPIC: Download unnamed web image?
http://groups.google.com/group/comp.lang.python/t/bbc7a4a86e42d7e9?hl=en
==============================================================================
== 1 of 6 ==
Date: Tues, Feb 16 2010 4:31 pm
From: galileo228
All,
My python program signs onto the student facebook at my school and,
given email addresses, returns the associated full name. If I were to
do this through a regular browser, there is also a picture of the
individual, and I am trying to get my program to download the picture
as well. The problem: the html code of the page does not point to a
particular file, but rather refers to (what seems like) a query.
So, if one went to the facebook and searched for me using my school
net id (msb83), the image of my profile on the results page is:
<img width="100" height="130" border="0" class="border" alt="msb83"
src="deliverImage.cfm?netid=MSB83">
Using BeautifulSoup, mechanize, and urllib, I've constructed the
following:
br.open("http://www.school.edu/students/facebook/")
br.select_form(nr = 1)
br.form['fulltextsearch'] = 'msb83' # this searches the facebook for
me
br.submit()
results = br.response().read()
soup = BeautifulSoup(results)
foo2 = soup.find('td', attrs={'width':'95'})
foo3 = foo2.find('a')
foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'})
# this just drills down to the <img> line and until this point the
program does not return an error
save_as = os.path.join('./', msb83 + '.jpg')
urllib.urlretrieve(foo4, save_as)
I get the following error msg after running this code:
AttributeError: 'NoneType' object has no attribute 'strip'
I can download the picture through my browser by right-clicking,
selecting save as, and then the image gets saved as
'deliverImage.cfm.jpeg.'
Are there any suggestions as to how I might be able to download the
image using python?
Please let me know if more information is needed -- happy to supply
it.
Matt
== 2 of 6 ==
Date: Tues, Feb 16 2010 5:48 pm
From: John Bokma
galileo228 <mattbarkan@gmail.com> writes:
> Using BeautifulSoup, mechanize, and urllib, I've constructed the
> following:
>
> br.open("http://www.school.edu/students/facebook/")
> br.select_form(nr = 1)
>
> br.form['fulltextsearch'] = 'msb83' # this searches the facebook for
> me
> br.submit()
> results = br.response().read()
> soup = BeautifulSoup(results)
> foo2 = soup.find('td', attrs={'width':'95'})
> foo3 = foo2.find('a')
> foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'})
> # this just drills down to the <img> line and until this point the
> program does not return an error
>
> save_as = os.path.join('./', msb83 + '.jpg')
> urllib.urlretrieve(foo4, save_as)
>
> I get the following error msg after running this code:
>
> AttributeError: 'NoneType' object has no attribute 'strip'
Wild guess, since you didn't provide line numbers, etc.
foo4 is None
(I also would like to suggest to use more meaningful names)
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
== 3 of 6 ==
Date: Tues, Feb 16 2010 6:40 pm
From: galileo228
On Feb 16, 8:48 pm, John Bokma <j...@castleamber.com> wrote:
> galileo228 <mattbar...@gmail.com> writes:
> > Using BeautifulSoup, mechanize, and urllib, I've constructed the
> > following:
>
> > br.open("http://www.school.edu/students/facebook/")
> > br.select_form(nr = 1)
>
> > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for
> > me
> > br.submit()
> > results = br.response().read()
> > soup = BeautifulSoup(results)
> > foo2 = soup.find('td', attrs={'width':'95'})
> > foo3 = foo2.find('a')
> > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'})
> > # this just drills down to the <img> line and until this point the
> > program does not return an error
>
> > save_as = os.path.join('./', msb83 + '.jpg')
> > urllib.urlretrieve(foo4, save_as)>
> > I get the following error msg after running this code:
>
> > AttributeError: 'NoneType' object has no attribute 'strip'
>
> Wild guess, since you didn't provide line numbers, etc.
>
> foo4 is None
>
> (I also would like to suggest to use more meaningful names)
>
> --
> John Bokma j3b
I thought it was too, and I just doublechecked. It's actually
foo3 = foo2.find('a')
that is causing the NoneType error.
Thoughts?
== 4 of 6 ==
Date: Tues, Feb 16 2010 6:54 pm
From: galileo228
On Feb 16, 9:40 pm, galileo228 <mattbar...@gmail.com> wrote:
> On Feb 16, 8:48 pm, John Bokma <j...@castleamber.com> wrote:
>
>
>
> > galileo228 <mattbar...@gmail.com> writes:
> > > Using BeautifulSoup, mechanize, and urllib, I've constructed the
> > > following:
>
> > > br.open("http://www.school.edu/students/facebook/")
> > > br.select_form(nr = 1)
>
> > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for
> > > me
> > > br.submit()
> > > results = br.response().read()
> > > soup = BeautifulSoup(results)
> > > foo2 = soup.find('td', attrs={'width':'95'})
> > > foo3 = foo2.find('a')
> > > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'})
> > > # this just drills down to the <img> line and until this point the
> > > program does not return an error
>
> > > save_as = os.path.join('./', msb83 + '.jpg')
> > > urllib.urlretrieve(foo4, save_as)>
> > > I get the following error msg after running this code:
>
> > > AttributeError: 'NoneType' object has no attribute 'strip'
>
> > Wild guess, since you didn't provide line numbers, etc.
>
> > foo4 is None
>
> > (I also would like to suggest to use more meaningful names)
>
> > --
> > John Bokma j3b
>
> I thought it was too, and I just doublechecked. It's actually
>
> foo3 = foo2.find('a')
>
> that is causing the NoneType error.
>
> Thoughts?
I've now fixed the foo3 issue, and I now know that the problem is with
the urllib.urlretrieve line (see above). This is the error msg I get
in IDLE:
Traceback (most recent call last):
File "/Users/Matt/Documents/python/dtest.py", line 59, in <module>
urllib.urlretrieve(foo4, save_as)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/urllib.py", line 94, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/urllib.py", line 226, in retrieve
url = unwrap(toBytes(url))
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/urllib.py", line 1033, in unwrap
url = url.strip()
TypeError: 'NoneType' object is not callable
Is this msg being generated because I'm trying to retrieve a url
that's not really a file?
== 5 of 6 ==
Date: Tues, Feb 16 2010 7:11 pm
From: John Bokma
galileo228 <mattbarkan@gmail.com> writes:
> On Feb 16, 9:40 pm, galileo228 <mattbar...@gmail.com> wrote:
[...]
> I've now fixed the foo3 issue, and I now know that the problem is with
> the urllib.urlretrieve line (see above). This is the error msg I get
> in IDLE:
>
> Traceback (most recent call last):
> File "/Users/Matt/Documents/python/dtest.py", line 59, in <module>
> urllib.urlretrieve(foo4, save_as)
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/urllib.py", line 94, in urlretrieve
> return _urlopener.retrieve(url, filename, reporthook, data)
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/urllib.py", line 226, in retrieve
> url = unwrap(toBytes(url))
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/urllib.py", line 1033, in unwrap
> url = url.strip()
> TypeError: 'NoneType' object is not callable
>
> Is this msg being generated because I'm trying to retrieve a url
> that's not really a file?
--8<---------------cut here---------------start------------->8---
>>> import urllib;
>>> urllib.urlretrieve(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/urllib.py", line 89, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "/usr/lib/python2.5/urllib.py", line 210, in retrieve
url = unwrap(toBytes(url))
File "/usr/lib/python2.5/urllib.py", line 1009, in unwrap
url = url.strip()
AttributeError: 'NoneType' object has no attribute 'strip'
--8<---------------cut here---------------end--------------->8---
To me it looks like you're still calling urlretrieve with None as a
first value.
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
== 6 of 6 ==
Date: Tues, Feb 16 2010 7:14 pm
From: Matthew Barnett
galileo228 wrote:
> On Feb 16, 9:40 pm, galileo228 <mattbar...@gmail.com> wrote:
>> On Feb 16, 8:48 pm, John Bokma <j...@castleamber.com> wrote:
>>
>>
>>
>>> galileo228 <mattbar...@gmail.com> writes:
>>>> Using BeautifulSoup, mechanize, and urllib, I've constructed the
>>>> following:
>>>> br.open("http://www.school.edu/students/facebook/")
>>>> br.select_form(nr = 1)
>>>> br.form['fulltextsearch'] = 'msb83' # this searches the facebook for
>>>> me
>>>> br.submit()
>>>> results = br.response().read()
>>>> soup = BeautifulSoup(results)
>>>> foo2 = soup.find('td', attrs={'width':'95'})
>>>> foo3 = foo2.find('a')
>>>> foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'})
>>>> # this just drills down to the <img> line and until this point the
>>>> program does not return an error
>>>> save_as = os.path.join('./', msb83 + '.jpg')
>>>> urllib.urlretrieve(foo4, save_as)>
>>>> I get the following error msg after running this code:
>>>> AttributeError: 'NoneType' object has no attribute 'strip'
>>> Wild guess, since you didn't provide line numbers, etc.
>>> foo4 is None
>>> (I also would like to suggest to use more meaningful names)
>>> --
>>> John Bokma j3b
>> I thought it was too, and I just doublechecked. It's actually
>>
>> foo3 = foo2.find('a')
>>
>> that is causing the NoneType error.
>>
>> Thoughts?
>
> I've now fixed the foo3 issue, and I now know that the problem is with
> the urllib.urlretrieve line (see above). This is the error msg I get
> in IDLE:
>
> Traceback (most recent call last):
> File "/Users/Matt/Documents/python/dtest.py", line 59, in <module>
> urllib.urlretrieve(foo4, save_as)
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/urllib.py", line 94, in urlretrieve
> return _urlopener.retrieve(url, filename, reporthook, data)
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/urllib.py", line 226, in retrieve
> url = unwrap(toBytes(url))
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
> python2.6/urllib.py", line 1033, in unwrap
> url = url.strip()
> TypeError: 'NoneType' object is not callable
>
> Is this msg being generated because I'm trying to retrieve a url
> that's not really a file?
It's because the URL you're passing in, namely foo4, is None. This is
presumably because foo3.find() returns None if it can't find the entry.
You checked the value of foo3, but did you check the value of foo4?
==============================================================================
TOPIC: Hubris connects Ruby to Haskell, will there be such a connection
between Python and Haskell?
http://groups.google.com/group/comp.lang.python/t/5b5a0c768c788353?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 16 2010 6:04 pm
From: Carl Banks
On Feb 16, 10:32 am, Casey Hawthorne <caseyhHAMMER_T...@istar.ca>
wrote:
> Hubris connects Ruby to Haskell, will there be such a connection
> between Python and Haskell?
I would have expected Hubris to link Ada and Common Lisp together.
Carl Banks
==============================================================================
TOPIC: Is there a simple way to find the list index to the max value?
http://groups.google.com/group/comp.lang.python/t/b8456fe748df61e2?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Feb 16 2010 8:44 pm
From: TomF
On 2010-02-16 11:44:45 -0800, aahz@pythoncraft.com (Aahz) said:
> In article <4B7A91B1.6030301@lonetwin.net>, steve <steve@lonetwin.net> wrote:
>> On 02/16/2010 05:49 PM, W. eWatson wrote:
>>>
>>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2.
>>
>> The most obvious would be a.index(max(a)). Is that what you wanted ?
>
> The disadvantage of that is that it's O(2N) instead of O(N).
I don't think you understand order notation. There's no such thing as O(2N).
To answer the original question, how about:
max(enumerate(l), key=lambda x: x[1])[0]
As to whether this is faster than index(max()), you'd have to time it.
-Tom
==============================================================================
TOPIC: The future of "frozen" types as the number of CPU cores increases
http://groups.google.com/group/comp.lang.python/t/7ef75c20d1be370d?hl=en
==============================================================================
== 1 of 4 ==
Date: Tues, Feb 16 2010 9:09 pm
From: John Nagle
Terry Reedy wrote:
> On 2/16/2010 3:15 PM, John Nagle wrote:
>> In the beginning, Python had some types which were "frozen",
> > and some which weren't.
>
> In the beginning, there was only one 'frozen' general purpose collection
> type, the tuple. And Guido resisted the suggestion that lists and tuple
> were mutable and frozen versions of each other.
>
> However, things have changed, and lists and tuple *are* effectively
> mutable and hashable versions of each other, and we have the three other
> pairs you mentioned. The idea of freeze() may have been floated (and
> punctured) during Py3 discussions, but I think it a fairly good one.
Yes, we're now at the point where all the built-in mutable types
have "frozen" versions. But we don't have that for objects. It's
generally considered a good thing in language design to offer,
for user defined types, most of the functionality of built-in ones.
It's the concurrency aspect of this that interests me, though.
A language with immutable objects can potentially handle concurrency
more safely than one where everything is potentially mutable.
The language knows what can't change, which simplifies locking.
John Nagle
== 2 of 4 ==
Date: Tues, Feb 16 2010 9:52 pm
From: Paul Rubin
John Nagle <nagle@animats.com> writes:
>> However, things have changed, and lists and tuple *are* effectively
>> mutable and hashable versions of each other...
> It's the concurrency aspect of this that interests me, though.
> A language with immutable objects can potentially handle concurrency
> more safely than one where everything is potentially mutable.
> The language knows what can't change, which simplifies locking.
I wonder how well that applies to tuples containing mutable objects,
e.g. t = ([1,2], [3,4])
== 3 of 4 ==
Date: Tues, Feb 16 2010 10:17 pm
From: "Alf P. Steinbach"
* Paul Rubin:
> John Nagle <nagle@animats.com> writes:
>>> However, things have changed, and lists and tuple *are* effectively
>>> mutable and hashable versions of each other...
>> It's the concurrency aspect of this that interests me, though.
>> A language with immutable objects can potentially handle concurrency
>> more safely than one where everything is potentially mutable.
>> The language knows what can't change, which simplifies locking.
>
> I wonder how well that applies to tuples containing mutable objects,
> e.g. t = ([1,2], [3,4])
One would need a collection type that's immutable "all the way".
Current frozen types don't have that.
However, there's also the question of the immutability of what names refer to.
It seems to me that this means that the compiler can't really assume very much
without very deep analysis. And so, if it boils down to the programmer applying
assumptions about mutability/constantness, then types may not be The Answer.
Cheers,
- Alf
== 4 of 4 ==
Date: Tues, Feb 16 2010 11:35 pm
From: Steven D'Aprano
On Tue, 16 Feb 2010 21:09:27 -0800, John Nagle wrote:
> Yes, we're now at the point where all the built-in mutable types
> have "frozen" versions. But we don't have that for objects. It's
> generally considered a good thing in language design to offer, for user
> defined types, most of the functionality of built-in ones.
It's not hard to build immutable user-defined types. Whether they're
immutable enough is another story :)
>>> class FrozenMeta(type):
... def __new__(meta, classname, bases, classDict):
... def __setattr__(*args):
... raise TypeError("can't change immutable class")
... classDict['__setattr__'] = __setattr__
... classDict['__delattr__'] = __setattr__
... return type.__new__(meta, classname, bases, classDict)
...
>>>
>>> class Thingy(object):
... __metaclass__ = FrozenMeta
... def __init__(self, x):
... self.__dict__['x'] = x
...
>>>
>>>
>>> t = Thingy(45)
>>> t.x
45
>>> t.x = 42
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __setattr__
TypeError: can't change immutable class
It's a bit ad hoc, but it seems to work for me. Unfortunately there's no
way to change __dict__ to a "write once, read many" dict.
--
Steven
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en
To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home