Thursday, March 11, 2010

comp.lang.python - 25 new messages in 17 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Insert missing keys using defaultdict - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/78157c74ab9c2e32?hl=en
* Can't define __call__ within __init__? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/6c1e03e9d76cf596?hl=en
* bypass UAC control through python script (to be run from batchfile) - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/0be68444d9e945d2?hl=en
* Python, Reportlabs, Pil and Windows 7 (64bit) - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/8f0199cb036d7949?hl=en
* Behavior of default parameter in a function - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b32b54c9a7888277?hl=en
* I get the error: ImportError: No module named ffnet - 2 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/2716fc6c0a3213cc?hl=en
* Named loops for breaking - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/96f3407480ed39ab?hl=en
* Anything like "Effective Java" for Python? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/47674ff2d2c78fa6?hl=en
* importing modules from subdirs - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/b27d784a170dd8e5?hl=en
* use of multiple versions of python - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f324fe75e6b1e387?hl=en
* unable to run wxPython script: dll errors - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/2db31e2cc1fa6a6e?hl=en
* Python Script to get Info from Site not working - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/4741fd660fb9b691?hl=en
* Visual Python programming and decompilers? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/920e010869d6b6fc?hl=en
* Get a method instance through 'getattr' but not superclass's method - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/17fe44173a924c48?hl=en
* Python 2.6 and modules dbi AND odbc - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6ca6877eabe3ecc3?hl=en
* file seek is slow - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f9c31a229cdda107?hl=en
* Where can I find documentation for data[:,9] - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/40f03fbaf8ae503f?hl=en

==============================================================================
TOPIC: Insert missing keys using defaultdict
http://groups.google.com/group/comp.lang.python/t/78157c74ab9c2e32?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Mar 11 2010 8:02 am
From: Gnarlodious


I am trying to grok this documentation but need help:
http://docs.python.org/library/collections.html#defaultdict-examples

In a perfect world the dict looks like this:
plistDict={'Style':'ExternalURL', 'Ref':'http://Gnarlodious.com/',
'Tip':'Opens in a new window', 'Text':'Gnarlodious.com'}

Let's say I want to prep a dict from a plist to insert the values into
an HTML link string:
"<a class='%(Style)s' href='%(Ref)s' title='%(Tip)s'>%(Text)s</a>" %
plistDict

However, in this imperfect world the dict might look like this:
plistDict={'Ref':'http://Gnarlodious.com/', 'Text':'Gnarlodious.com'}

which would error:
KeyError: 'Style'

So using defaultdict:
from collections import defaultdict

How do create a dict assigning every missing key with a default
string?

-- Gnarlie


== 2 of 3 ==
Date: Thurs, Mar 11 2010 8:20 am
From: George Sakkis


On Mar 11, 5:02 pm, Gnarlodious <gnarlodi...@gmail.com> wrote:

> I am trying to grok this documentation but need help:http://docs.python.org/library/collections.html#defaultdict-examples
>
> In a perfect world the dict looks like this:
> plistDict={'Style':'ExternalURL', 'Ref':'http://Gnarlodious.com/',
> 'Tip':'Opens in a new window', 'Text':'Gnarlodious.com'}
>
> Let's say I want to prep a dict from a plist to insert the values into
> an HTML link string:
> "<a class='%(Style)s' href='%(Ref)s' title='%(Tip)s'>%(Text)s</a>" %
> plistDict
>
> However, in this imperfect world the dict might look like this:
> plistDict={'Ref':'http://Gnarlodious.com/', 'Text':'Gnarlodious.com'}
>
> which would error:
> KeyError: 'Style'
>
> So using defaultdict:
> from collections import defaultdict
>
> How do create a dict assigning every missing key with a default
> string?

"<a class='%(Style)s' href='%(Ref)s' title='%(Tip)s'>%(Text)s</a>" %
defaultdict(lambda:'_MISSING_', plistDict)

HTH,
George


== 3 of 3 ==
Date: Thurs, Mar 11 2010 8:27 am
From: Gnarlodious


On Mar 11, 9:20 am, George Sakkis wrote:

> > How do create a dict assigning every missing key with a default
> > string?
>
> "<a class='%(Style)s' href='%(Ref)s' title='%(Tip)s'>%(Text)s</a>" %
> defaultdict(lambda:'_MISSING_', plistDict)

Brilliant, I love Python.

-- Gnarlie


==============================================================================
TOPIC: Can't define __call__ within __init__?
http://groups.google.com/group/comp.lang.python/t/6c1e03e9d76cf596?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Mar 11 2010 8:20 am
From: Steve Howell


On Mar 10, 7:18 pm, Steven D'Aprano
<ste...@REMOVE.THIS.cybersource.com.au> wrote:
> On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote:
> > Want to switch __call__ behavior.  Why doesn't this work?  What is the
> > correct way to write this?
>
> > class X (object):
> >     def __init__(self, i):
> >         if i == 0:
> >             def __call__ (self):
> >                 return 0
> >         else:
> >             def __call_ (self):
> >                 return 1
>
> Others have already pointed out that there are two reasons that won't
> work:
>
> (1) you define __call__ as a local variable of the __init__ method which
> then disappears as soon as the __init__ method completes; and
>
> (2) special methods like __call__ are only called on the class, not the
> instance, so you can't give each instance its own method.
>

Are you sure about that? This program prints 1, 2, 1, 2.

class Foo:
def __init__(self, a):
if a == 1:
self.__call__ = lambda: 1
else:
self.__call__ = lambda: 2

foo1 = Foo(1)
print foo1()

foo2 = Foo(2)
print foo2()

print foo1()
print foo2()

See here:

http://docs.python.org/reference/datamodel.html

Class instances
Class instances are described below. Class instances are callable
only when the class has a __call__() method; x(arguments) is a
shorthand for x.__call__(arguments).


== 2 of 2 ==
Date: Thurs, Mar 11 2010 8:36 am
From: Peter Otten <__peter__@web.de>


Steve Howell wrote:

> On Mar 10, 7:18 pm, Steven D'Aprano
> <ste...@REMOVE.THIS.cybersource.com.au> wrote:

>> (2) special methods like __call__ are only called on the class, not the
>> instance, so you can't give each instance its own method.

> Are you sure about that? This program prints 1, 2, 1, 2.

You are using a classic class while the behaviour described above applies to
newstyle classes:

>>> class Foo:
... def __init__(self):
... self.__call__ = lambda: 42
...
>>> Foo()()
42
>>> class Bar(object):
... def __init__(self):
... self.__call__ = lambda: 42
...
>>> Bar()()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'Bar' object is not callable

I don't think it's a good idea to write new code that requires a classic
class.

Peter

==============================================================================
TOPIC: bypass UAC control through python script (to be run from batchfile)
http://groups.google.com/group/comp.lang.python/t/0be68444d9e945d2?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 8:28 am
From: "rizwanahmed24@gmail.com"


Hi

here is my problem.

i want to install a program through python script. The python scripts
is called from a batch file. The UAC control is not allowing the
python script to install a msi (installer). I need to somehow by pass
the UAC control. i dont want to turn it off permanently. Once i have
run the batch file, i do not interact with the system manually,
therefore Clicking allow on UAC dialog is not the solution for me.

i just want to achieve the goal, whether i run batch file in Admin
mode, or do it form python, doesnt matter.
any ideas?

//Rizwan

==============================================================================
TOPIC: Python, Reportlabs, Pil and Windows 7 (64bit)
http://groups.google.com/group/comp.lang.python/t/8f0199cb036d7949?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Mar 11 2010 8:29 am
From: Robin Becker


On 11/03/2010 13:55, Astley Le Jasper wrote:
> I have a Windows 7 (64bit AMD) machine and am having quite a lot of
> problems installing Reportlabs and Pil. I wondered if anyone else has
> had the same issues and what the best way of dealing with it.
>
> So far I've tried:
>
> 1. Reportlabs / Pil 32 installers - I've tried using these but they
> can't find python. I also tried registering Python (http://effbot.org/
> zone/python-register.htm) but this also fails.
> 2. Reportlabs / Pil Source - I downloaded each of these and tried to
> do a "python setup.py install". However, both complain that they can't
> find "vcvarsall.bat". I've done some checking and it's because the
> compiler isn't present. Everyone is suggesting downloading Visual
> Studio Express C++, but this only comes with the 32bit compiler. There
> seems to be quite a lot of work to get 64bit VSE working on a 64bit
> machine (http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-
> express-edition-and-64-bit-targets/).
>
> But before I start down that path, I wondered if anyone had any advice
> (.... and no I don't mean suggesting I swap to Linux).
>
> ALJ

Hi,

you might get more assistance on the reportlab users mailing list at

http://two.pairlist.net/mailman/listinfo/reportlab-users

We do have users that run both reportlab & pil on 64 bit linux architectures,
but I don't think I have ever compiled any of the extensions for 64bit windows.
The vcvarsall.bat reference is the distutils package desperately looking for a
suitable compiler (and not finding it).

Perhaps some expert on the python list knows which versions of VS support 64bit;
I do have VS 2005/2008 etc, but I'll probably need to set up a 64bit machine to
see if they will install on a 64bit architecture.
--
Robin Becker

== 2 of 2 ==
Date: Thurs, Mar 11 2010 10:00 am
From: "Martin v. Loewis"

>> I have a Windows 7 (64bit AMD) machine

This is somewhat imprecise: is it
a) that your CPU is AMD64, and thus supports 64-bit mode, or
b) that *in addition*, your Windows 7 installation is a 64-bit
installation, or
c) that *in addition*, your Python installation is also a 64-bit
installation.

Unless you have a specific need for 64-bit mode, I recommend that you
use the 32-bit version of Windows (unless you have more than 4GB of
main memory), and (even if you have a 64-bit Windows) you install the
32-bit version of Python on it (unless you have the need to access more
than 2GB of objects in your Python applications.

>> 1. Reportlabs / Pil 32 installers - I've tried using these but they
>> can't find python. I also tried registering Python (http://effbot.org/
>> zone/python-register.htm) but this also fails.

Install the 32-bit version of Python, and these installers should work fine.

> Perhaps some expert on the python list knows which versions of VS
> support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set
> up a 64bit machine to see if they will install on a 64bit architecture.

For Python 2.6 and later, use VS 2008. This comes with an AMD64
compiler. You technically don't need a 64-bit Windows, as it supports
cross-compilation (but you would need a 64-bit Windows to test it).

I personally build Python on a 32-bit machine, and move the MSI to a
64-bit machine for testing.

Regards,
Martin

==============================================================================
TOPIC: Behavior of default parameter in a function
http://groups.google.com/group/comp.lang.python/t/b32b54c9a7888277?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 8:48 am
From: Gary Herron


This is addressed in the FAQ.


http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects

jitendra gupta wrote:
>
> def foo(x = [0]):
> x[0] = x[0] + 1
> return x[0]
>
> def soo(x = None):
> if x is None:
> x = [0]
> x[0] = x[0] + 1
> return x[0]
>
> >>> foo()
> 1
> >>>foo() #See the behavior incremented by one
> 2
> >>>foo([1]) # but here based on given number
> 2
> >>>foo()
> 3
> >>>foo([1])
> 2
> >>>foo()
> 4
>
> >>>soo()
> 1
> >>>soo()
> 1
> >>>soo([1])
> 2
> >>>soo()
> 1
>
> Why foo() is incremented by 1 always when we are not passing any argument,
> but this is not happening in soo() case, In which scenario
> we will use these type of function.'
>
> Thanks
> Jitendra Kumar
>


==============================================================================
TOPIC: I get the error: ImportError: No module named ffnet
http://groups.google.com/group/comp.lang.python/t/2716fc6c0a3213cc?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Mar 11 2010 9:04 am
From: " Cal Who"


I ran this:
import sys

from pprint import pprint as pp

pp(sys.path)

The output included:

'E:\\Program Files\\Python26',

'E:\\Program Files\\Python26\\DLLs',

'E:\\Program Files\\Python26\\lib',

'E:\\Program Files\\Python26\\lib\\lib-tk',

'E:\\Program Files\\Python26\\lib\\plat-win',

'E:\\Program Files\\Python26\\lib\\site-packages',

Python is at

E:\Python26

but other things like java are at E:\Program Files

Showhow it is looking in the wrong place and I don't know how to fix it.

I checked the registry. The entries all look good there.

Thanks

" Cal Who" <CalWhoNOSPAM@roadrunner.com> wrote in message
news:hnb339$g2g$1@news.eternal-september.org...
>
>
> I have the .py file in Eclipse
> #@PydevCodeAnalysisIgnore
> from ffnet import ffnet, mlgraph
> topology = mlgraph( (2, 3, 1) )
> nn = ffnet(topology)
>
> I select RunAs / Python Run
>
> I get the error
> from ffnet import ffnet, mlgraph
> ImportError: No module named ffnet
>
> In the folder Python26\lib\site-packages I see
> ffnet-0.6.2-py2.6.egg-info
>
> also a folder ffnet
> in that folder there is a folder Examples
> If I click one of the examples pyrhon.exe opens and runs it OK.
>
> Is there enough in the above for you to tell me how to procede?
>
> Thanks in advance for any help at all
>
>
>


== 2 of 2 ==
Date: Thurs, Mar 11 2010 10:56 am
From: " Cal Who"


I found out I had something installed wrong.

" Cal Who" <CalWhoNOSPAM@roadrunner.com> wrote in message
news:hnb339$g2g$1@news.eternal-september.org...
>
>
> I have the .py file in Eclipse
> #@PydevCodeAnalysisIgnore
> from ffnet import ffnet, mlgraph
> topology = mlgraph( (2, 3, 1) )
> nn = ffnet(topology)
>
> I select RunAs / Python Run
>
> I get the error
> from ffnet import ffnet, mlgraph
> ImportError: No module named ffnet
>
> In the folder Python26\lib\site-packages I see
> ffnet-0.6.2-py2.6.egg-info
>
> also a folder ffnet
> in that folder there is a folder Examples
> If I click one of the examples pyrhon.exe opens and runs it OK.
>
> Is there enough in the above for you to tell me how to procede?
>
> Thanks in advance for any help at all
>
>
>

==============================================================================
TOPIC: Named loops for breaking
http://groups.google.com/group/comp.lang.python/t/96f3407480ed39ab?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 9:22 am
From: "bartc"


James Harris wrote:
> On 10 Mar, 06:29, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
>> En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein <bri...@gmail.com>
>> escribi :
>>
>>> Basically I'm wondering if there are any plans to implemented named
>>> loops in Python, so I can tell a break command to break out of a
>>> specific loop in the case of nested loops.
>>
>> See PEP3136 [1] and its rejection note [2]
>> I think you may find some more discussion in the python-ideas list.

> Breaking out of an inner loop is just as natural as breaking out of
> the immediately enclosing loop. ISTM that if one is allowed the other
> should be also.

Exactly. Python already has single-level break (probably some baggage
carried over from C), and some of the same arguments can be applied to that
too.

Given that break does exist, it's annoying that in the followed contrived
example:

def f(n):
return n==2

for i in range(10):
print i
if f(0): break
if f(1): break
if f(2): break
if f(3): break

I can't turn the list of ifs into a loop. I can use break embedded inside a
statement inside a loop, provided it's not another loop! That's
discrimination...

> There are often times when it *is* better to factor out the code to a
> different function but adding a function just to enable a break from
> an inner loop doesn't seem to me a good reason.

Multi-level breaks should just have been part of the language, so they are
available to those who want them, and ignored by everyone else.

(And in languages where I've implemented them -- all generally faster than
Python -- they have no impact on performance. I also had 4 loop controls
rather than just 2, all multi-level, and the world hasn't ended yet.)

My experience of these break statements is that they are used infrequently
in final code. But they are handy when developing code too: you don't want
to waste time refactoring, and generally turning code upside-down, when the
code has to be rewritten a dozen times anyway.

--
Bartc


==============================================================================
TOPIC: Anything like "Effective Java" for Python?
http://groups.google.com/group/comp.lang.python/t/47674ff2d2c78fa6?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 9:28 am
From: mk


kj wrote:
>
>
> Subject line pretty much says it all: is there a book like "Effective
> Java" for Python. I.e. a book that assumes that readers are
> experienced programmers that already know the basics of the language,
> and want to focus on more advanced programming issues?

I'm surprised nobody mentioned Dive Into Python:

http://diveintopython.org/

Available for free online. Most Python books contain a lot of 'hello
world' material which for someone who knows at least one programming
language is boring, this one doesn't, it cuts straight to the point. I
found it very readable.

Regards,
mk


==============================================================================
TOPIC: importing modules from subdirs
http://groups.google.com/group/comp.lang.python/t/b27d784a170dd8e5?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Mar 11 2010 9:51 am
From: Alex Hall


Hi all,
The manual says, for modules in a project stored in subdirectories, you can do:
import folderName.module

I have a couple questions, though:
1. Do I then have to call functions from module like
folder.module.function, or can I still use the normal module.function?

2. When I try to do this, it fails. I have an sw folder. Inside that I
have a modes folder, holding weather.pyw. Main.pyw, back in the sw
folder, is trying to import modes.weather, but nothing happens. I have
tried putting weather.pyw in its own weather folder under the modes
folder, but that also fails. I have placed an empty __init__.py file
in both the modes folder and the weather subfolder, but I cannot get
main.pyw to import weather!

3. How does weather import from a folder above or beside it? For
example, if a config directory is at the same level as the modes
directory, how can weather import something from config?

Thanks!

--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.com/mehgcap


== 2 of 3 ==
Date: Thurs, Mar 11 2010 10:00 am
From: Gary Herron


Alex Hall wrote:
> Hi all,
> The manual says, for modules in a project stored in subdirectories, you can do:
> import folderName.module
>
> I have a couple questions, though:
> 1. Do I then have to call functions from module like
> folder.module.function, or can I still use the normal module.function?
>

Either, depending on how you do the import:

import folder.module
folder.module.function()

or

from folder.module import function
function()

or

from folder import module
module.function()

> 2. When I try to do this, it fails. I have an sw folder. Inside that I
> have a modes folder, holding weather.pyw. Main.pyw, back in the sw
> folder, is trying to import modes.weather, but nothing happens. I have
> tried putting weather.pyw in its own weather folder under the modes
> folder, but that also fails. I have placed an empty __init__.py file
> in both the modes folder and the weather subfolder, but I cannot get
> main.pyw to import weather!
>

Show us some code and a diagram of your forcer hierarchy, and we'll look
at it.
> 3. How does weather import from a folder above or beside it? For
> example, if a config directory is at the same level as the modes
> directory, how can weather import something from config?
>

You don't import from up the hierarchy. You can put a higher folder on
sys.path, and get to it that way.

Gary Herron


> Thanks!
>
>

== 3 of 3 ==
Date: Thurs, Mar 11 2010 10:10 am
From: Steve Holden


Alex Hall wrote:
> Hi all,
> The manual says, for modules in a project stored in subdirectories, you can do:
> import folderName.module
>
> I have a couple questions, though:
> 1. Do I then have to call functions from module like
> folder.module.function, or can I still use the normal module.function?
>
> 2. When I try to do this, it fails. I have an sw folder. Inside that I
> have a modes folder, holding weather.pyw. Main.pyw, back in the sw
> folder, is trying to import modes.weather, but nothing happens. I have
> tried putting weather.pyw in its own weather folder under the modes
> folder, but that also fails. I have placed an empty __init__.py file
> in both the modes folder and the weather subfolder, but I cannot get
> main.pyw to import weather!
>
> 3. How does weather import from a folder above or beside it? For
> example, if a config directory is at the same level as the modes
> directory, how can weather import something from config?
>
> Thanks!
>
I haven't checked this, but I believe .pyw names are only for main
programs. Try renaming weather.pyw as weather.py and see if it makes any
difference.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/


==============================================================================
TOPIC: use of multiple versions of python
http://groups.google.com/group/comp.lang.python/t/f324fe75e6b1e387?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 10:14 am
From: David Robinow


On Thu, Mar 11, 2010 at 12:40 AM, Bujji <sivaits4u@gmail.com> wrote:
> hi all,
> I have installed python 2.6 in addition to python 2.5 in my system
> Now for some modules(while installing ) it needs to use python 2.6
> how can i do that
> in case of easy_install what should i do to it to use python 2.6
You should have an easy_install-2.5 and easy_install-2.6. One of
them will be linked to easy_install, depending on how you did the
install. Just use the one you need.

==============================================================================
TOPIC: unable to run wxPython script: dll errors
http://groups.google.com/group/comp.lang.python/t/2db31e2cc1fa6a6e?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 10:15 am
From: Alex Hall


Hi all,
I am trying to run a file that should pop up a dialog. The dialog is
fine (I used XRCed to create it and running it from within that editor
brings up the dialog I want). When I run my file, though, I get this
traceback:

C:\Users\Alex>c:\python26\python.exe i:\arm\dictionary.py
Traceback (most recent call last):
File "i:\arm\dictionary.py", line 2, in <module>
import wx
File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4
5, in <module>
from wx._core import *
File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i
n <module>
import _core_
ImportError: DLL load failed: The specified procedure could not be found.

I am running win7x64, wxPython2.8, python2.6. Any ideas why this would
be happening? I found a forum post that talked about a manifest file
and some dll files being needed, but it did not make a lot of sense.
Thanks!


--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.com/mehgcap

==============================================================================
TOPIC: Python Script to get Info from Site not working
http://groups.google.com/group/comp.lang.python/t/4741fd660fb9b691?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 10:28 am
From: "Gabriel Genellina"


En Wed, 10 Mar 2010 23:26:05 -0300, Jimbo <nilly16@yahoo.com> escribió:

> On Mar 11, 12:38 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
> wrote:
>> En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo <nill...@yahoo.com> escribió:
>>
>> > I found a semi Python & internet tutorial here if anyone else would
>> > like ithttp://www.upriss.org.uk/python/session6.html
>>
>> Replace the last line with something like this, to see what you are
>> getting exactly:
>>
>> print("Sorry, no %r (%r) available." % (
>> drink,
>> cgi.escape(repr(type(drink)))))
>>
>> BTW, which Python version are you using? The tutorial you linked to is
>> aimed at Python 2.x, but your print syntax suggests you're using Python
>> 3.x

> I am using 3.x, do you think I should be using something else?

Yes, you should use the same version as the tutorial you're following.
Learning how to program, CGI, HTML and Python at the same time is hard
enough to complicate it with incompatible version differences. I suggest
Python 2.6.4

> Also
> the your code I put in does the some thing, just now it says "Sorry no
> none drink available" all the time.

As a general rule, always directly copy and paste the error messages you
get and the source code you execute. Do not retype or paraphrase them.
That's important for the rest of us to be able to help you - now and in
the future.

In this case, the message should read "Sorry, no None (<type 'NoneType'>)
available." (None, not none, is a built-in special object in Python). So
we know that drink is None instead of one of the expected values, and we
could start investigating why. But there is no point in digging further -
instead, downgrade to Python 2.6.4 and try again.
This might be a server issue, unrelated to your script. BTW, you didn't
mention the server software.

--
Gabriel Genellina


==============================================================================
TOPIC: Visual Python programming and decompilers?
http://groups.google.com/group/comp.lang.python/t/920e010869d6b6fc?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 10:38 am
From: Ludolph


Hi Guys

At work I have been exposed to a Agile Platform called OutSystems. It
allows you to visually program your web applications
http://i.imgur.com/r2F0i.png and I find the idea very intriguing.

So I have started to play around with the idea on how will I be able
to visually represent Python code as in the above image and then allow
the programmer to change some of the flow/code/logic visually and then
get it back as python source code. I don't know if this have been
tried before and after some googling I can't find anything like this,
so maybe I'm just lacking basic googling skills or a python solution
like the above does not exist yet.

If anybody knows of such solution please let me know, so that I don't
spend a lot of time recreating the wheel. Otherwise help me out on the
following problem:

I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to
disassemble the code to workable objects, It even allows me to rebuild
the objects to bytecode. So if I define patterns on how python
interrupts the source code to bytecode I can visually represent this
and also so convert my visual representations back to bytecode.

The only problem I have at the moment is how will I get this bytecode
back to python source code. I have googled for python decompiler but
only found old projects like unpyc, decompyle and some online
services. I would like to know if anybody know of a well maintained or
at least recent module that can help me accomplish the above
mentioned, because I'm hoping I can implement this in Python 3.1.

So any input or suggestion would be greatly appreciated.

Kind Regards,

--
Ludolph Neethling

==============================================================================
TOPIC: Get a method instance through 'getattr' but not superclass's method
http://groups.google.com/group/comp.lang.python/t/17fe44173a924c48?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 10:45 am
From: "Gabriel Genellina"


En Thu, 11 Mar 2010 01:47:30 -0300, Radhakrishna Bhat
<radhakrishna12@gmail.com> escribi�:

> I am using getattr to get a method instance from a class. But it also
> returns methods from the superclass. How to detect if an attribute is
> from
> superclass?

You may look it up directly in the class dictionary (__dict__)

--
Gabriel Genellina


==============================================================================
TOPIC: Python 2.6 and modules dbi AND odbc
http://groups.google.com/group/comp.lang.python/t/6ca6877eabe3ecc3?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 10:54 am
From: Kev Dwyer


On Wed, 10 Mar 2010 16:17:29 -0800, robert somerville wrote:

> hi;
> i am trying to get some legacy python code (which i no nothing about)
> working with tries to import dbi and odbc (the import fails ...) it
> looks like these modules are deprecated ?? if so is there a work around
> , if not deprecated, what am i doing wrong ?? i see no Ubuntu packages
> that look promising ..

Hello Robert,

These modules are distributed as part of the PyWin32 Python for Windows
extensions, so they need to run on a Windows box. They'll run fine
there regardless of the deprecation of dbi (though "import dbi" will
provide a useful warning message).

Pyodbc is a possible alternative.

Cheers,

Kev


==============================================================================
TOPIC: file seek is slow
http://groups.google.com/group/comp.lang.python/t/f9c31a229cdda107?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Mar 11 2010 11:01 am
From: Metalone


I am assuming that Python delegates the f.seek call to the seek call
in the MS C runtime library msvcrt.dll.
Does anybody know a nice link to the Python source like was posted
above for the BSD 'C' library?

Ok, I ran some more tests.
C, seek : 0.812 seconds // test from original post
Python, f.seek : 1.458 seconds. // test from original post

C, time(&tm) : 0.671 seconds
Python, time.time(): 0.513 seconds.
Python, ctypes.msvcrt.time(ctypes.byref(tm)): 0.971 seconds. #
factored the overhead to be outside the loop, so really this was
func_ptr(ptr).

Perhaps I am just comparing apples to oranges.
I never tested the overhead of ctypes like this before.
Most of my problem timings involve calls through ctypes.

==============================================================================
TOPIC: Where can I find documentation for data[:,9]
http://groups.google.com/group/comp.lang.python/t/40f03fbaf8ae503f?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Mar 11 2010 11:01 am
From: " Cal Who"


data = readdata( 'data/input.dat', delimiter = ',' )

input = data[:, :9]#nine data columns

Where can I find documentation for the

data[:,9]

in the code above.

Been looking and found many examples but would like to know the definition.

I need to skip the first column and then read 9

I would also like to print the data in ihe variable "input"

Thanks


== 2 of 2 ==
Date: Thurs, Mar 11 2010 11:22 am
From: Robert Kern


On 2010-03-11 13:01 PM, Cal Who wrote:
> data = readdata( 'data/input.dat', delimiter = ',' )
>
> input = data[:, :9]#nine data columns
>
>
>
> Where can I find documentation for the
>
> data[:,9]
>
> in the code above.
>
> Been looking and found many examples but would like to know the definition.

When asking questions like this, it helps *a lot* to provide a complete example,
not just a snippet. If I weren't already intimately familiar with the library
you are using, I would have no idea how to help you.

However, I do know that input object is a numpy array, and the syntax you are
asking about is multidimensional slicing.

http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

> I need to skip the first column and then read 9

data[:, 1:10]

> I would also like to print the data in ihe variable "input"

print input

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

==============================================================================

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


Real Estate