Re: Newbie python questions...

2012-04-14 Thread Steven D'Aprano
On Sat, 14 Apr 2012 11:25:57 -0700, vmars316 wrote: > win7HomePremium: > Greetings, > 1) > I installed portablePython(pP) here: > C:\Users\vmars\Python3 > ?Does that look ok? Sure, why not? > 2) > I would like to try pyWin, but it won't let me install because there is > no pP3.2 in registry. >

Re: Python Gotcha's?

2012-04-14 Thread Steven D'Aprano
On Sat, 14 Apr 2012 15:47:54 -0700, Bryan wrote: > Miki Tebeka wrote: >> If you have an interesting/common "Gotcha" (warts/dark corners ...) >> please share. > > Python 3(K) likes to use the same '.py' file extension as its > incompatible predecessors, And so it should. Python 2 and Python 3 a

Re: Python Gotcha's?

2012-04-14 Thread MRAB
On 14/04/2012 23:47, Bryan wrote: Miki Tebeka wrote: If you have an interesting/common "Gotcha" (warts/dark corners ...) please share. Python 3(K) likes to use the same '.py' file extension as its incompatible predecessors, and in some/many/most *nix implementations, it likes to install in t

Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Chris Angelico
On Sun, Apr 15, 2012 at 9:00 AM, MRAB wrote: > re.match(...) returns either a match object or None. In a condition, a > match object always evaluates as True and None always evaluates as > False. Yes, should have clarified that. It's a deliberate feature of the re module that you can do this. Ver

Re: Python Gotcha's?

2012-04-14 Thread Chris Angelico
On Sun, Apr 15, 2012 at 8:47 AM, Bryan wrote: > Python 3(K) likes to use the same '.py' file extension as its > incompatible predecessors, and in some/many/most *nix implementations, > it likes to install in the same place. Python 3 is an improvement upon > Python 2, but Python went from, "sure...

Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread MRAB
On 14/04/2012 23:45, Chris Angelico wrote: On Sun, Apr 15, 2012 at 8:41 AM, Mahmoud Abdel-Fattah wrote: item['author_brand'] = author_brand.group(2) if type(author_brand) != None else '' Almost there! :) None is a singleton, not a type; you don't need to check type(author_brand) but rathe

Re: Python Gotcha's?

2012-04-14 Thread Bryan
Miki Tebeka wrote: > If you have an interesting/common "Gotcha" (warts/dark corners ...) please > share. Python 3(K) likes to use the same '.py' file extension as its incompatible predecessors, and in some/many/most *nix implementations, it likes to install in the same place. Python 3 is an impro

Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Chris Angelico
On Sun, Apr 15, 2012 at 8:41 AM, Mahmoud Abdel-Fattah wrote: > item['author_brand'] = author_brand.group(2) if type(author_brand) != None > else '' Almost there! :) None is a singleton, not a type; you don't need to check type(author_brand) but rather its identity. Use "author_brand is not None"

Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Mahmoud Abdel-Fattah
Thanks ChrisA a lot. I just tried what you said, but I got an error, here's what I tried : item['name'] = hxs.select('//div[@id="center-main"]/h1/text()').extract()[0] author_brand = re.match(r'^[.*] - (.*)$', item['name'], re.I|re.S|re.M) item['author_brand'] = author_brand.group(2) if type(autho

Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Zero Piraeus
: > 1. How can I write the following code in easier way in Python ? > if len(item['description']) > 0: >             item['description'] = item['description'][0] >         else: >             item['description'] = '' Assuming item['description'] is a string, all you need is >>> item['description

Re: Naming future objects and their methods

2012-04-14 Thread Chris Angelico
On Sun, Apr 15, 2012 at 8:22 AM, Stefan Schwarzer wrote: > The future object returned by `put_bytes` has a `was_sent` > method which will return `True` once the sender thread has > actually sent the data via a socket call. Dunno if this throws a spanner in your works, but does the future object e

Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Chris Angelico
On Sun, Apr 15, 2012 at 8:16 AM, Mahmoud Abdel-Fattah wrote: > Hello, > > I'm coming from PHP background ant totally new to Python, I just started > using scrapy, but has some generic question in python. > > 1. How can I write the following code in easier way in Python ? > if len(item['description

Naming future objects and their methods

2012-04-14 Thread Stefan Schwarzer
Hello, I wrote a `Connection` class that can be found at [1]. A `Connection` object has a method `put_bytes(data)` which returns a "future" [2]. The data will be sent asynchronously by a thread attached to the connection object. The future object returned by `put_bytes` has a `was_sent` method wh

[newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Mahmoud Abdel-Fattah
Hello, I'm coming from PHP background ant totally new to Python, I just started using scrapy, but has some generic question in python. 1. How can I write the following code in easier way in Python ? if len(item['description']) > 0: item['description'] = item['description'][0]

Re: Newbie python questions...

2012-04-14 Thread Emile van Sebille
On 4/14/2012 11:25 AM vmars316 said... win7HomePremium: Greetings, 1) I installed portablePython(pP) here: C:\Users\vmars\Python3 ?Does that look ok? 2) I would like to try pyWin, but it won't let me install because there is no pP3.2 in registry. ? How can I update the Registry for Python3.2

Re: Zipping a dictionary whose values are lists

2012-04-14 Thread Arnaud Delobelle
On 13 April 2012 17:35, Kiuhnm wrote: > On 4/13/2012 17:58, Alexander Blinne wrote: >> >> zip(*[x[1] for x in sorted(d.items(), key=lambda y: y[0])]) > > Or >  zip(*[d[k] for k in sorted(d.keys())]) .keys() is superfluous here: zip(*(d[k] for k in sorted(d))) -- Arnaud -- http://mail.pyth

Re: Newbie python questions...

2012-04-14 Thread Temia Eszteri
>3) When ever I cllick on *.py file, >it runs by so fast that I can't see what's going on. > ?Is there a way to keep the pyconsole open 'til i decide to close >it? >Thanks...Vernon This one's answered easily enough - just open a command prompt window at that directory (shift-right click the folder

Re: Newbie python questions...

2012-04-14 Thread Andrew Berg
On 4/14/2012 1:25 PM, vmars316 wrote: > I installed portablePython(pP) here: > C:\Users\vmars\Python3 > ?Does that look ok? I would suggest including the minor version number (i.e. Python32 instead of Python3) because not all 3.x code is compatible with all versions of Python 3.x - all code that w

Newbie python questions...

2012-04-14 Thread vmars316
win7HomePremium: Greetings, 1) I installed portablePython(pP) here: C:\Users\vmars\Python3 ?Does that look ok? 2) I would like to try pyWin, but it won't let me install because there is no pP3.2 in registry. ? How can I update the Registry for Python3.2 ? 3) When ever I cllick on *.py file, it ru

Re: trac.util

2012-04-14 Thread Alex Willmer
On Apr 11, 9:52 pm, cerr wrote: > Hi, > > I want to install some python driver on my system that requires trac.util > (from Image.py) but I can't find that anywhere, any suggestions, anyone? > > Thank you very much, any help is appreciated! > > Error: > File "/root/weewx/bin/Image.py", line 32, i

Re: Python one-liner?

2012-04-14 Thread Tim Chase
On 04/13/12 22:54, Chris Angelico wrote: Yes, that would be the right method to use. I'd not bother with the function and map() though, and simply iterate: d = {} for val in l: d.setdefault(f(val), []).append(val) Or make d a defaultdict: from collections import defaultdict d = defaultd