[Tutor] get a module's own (top_level) dict?

2008-11-09 Thread spir

Hello pyhonistas,

Example:
=== module content ===
a = 1
b = 2
==

I'm looking for a way to get something like {'a':a, b':2}. Actually, names 
defind in the module will be instances of a custom type. I want to give them an 
attribute that holds their own name. E.g.:

for key,obj in dict:
obj.name = key
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Upgrading from Python 2.5 to Python 2.6 - IDLE not working...

2008-11-09 Thread Lie Ryan
On Sat, 08 Nov 2008 18:34:54 -0500, Dan wrote:

> Hi All,
> 
> This is my first post, so I apologize in advance for any etiquette
> violations.
> 
> I am interested in learning Python, and to that end, I undertook to
> upgrade my current version of Python 2.5 (available via openSUSE
> repositories and YaST) to Python 2.6.  I have Python 2.6 running
> (compiled from source [I'm not a total bonehead]) but idle gives me the
> following when I invoke it in bash:
> 
> [EMAIL PROTECTED]:~> idle
> Traceback (most recent call last):
>   File "/usr/local/bin/idle", line 3, in  from idlelib.PyShell
>   import main
>   File "/usr/local/lib/python2.6/idlelib/PyShell.py", line 14, in
>import macosxSupport
>   File "/usr/local/lib/python2.6/idlelib/macosxSupport.py", line 6, in
> 
>   import Tkinter
>   File "/usr/local/lib/python2.6/lib-tk/Tkinter.py", line 39, in
>import _tkinter # If this fails your Python may not be
>   configured for Tk
> ImportError: No module named _tkinter [EMAIL PROTECTED]:~>
> 
> I thought of unistalling and reinstalling (using YaST) the associated
> Python packages to make them aware of the version change, but the Idle
> package says it requires Python 2.5.2, nothing more or less, so I didn't
> attempt it.
> 
> Thanks in advance for your patience.
> 
> Dan

FYI, I've got idle running with python2.6

Python 2.6 (r26:66714, Oct 19 2008, 19:48:03) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "copyright", "credits" or "license()" for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 2.6  
>>> 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get a module's own (top_level) dict?

2008-11-09 Thread Lie Ryan
On Sun, 09 Nov 2008 11:34:37 +0100, spir wrote:

> Hello pyhonistas,
> 
> Example:
> === module content ===
> a = 1
> b = 2
> ==
> 
> I'm looking for a way to get something like {'a':a, b':2}. Actually,
> names defind in the module will be instances of a custom type. I want to
> give them an attribute that holds their own name. E.g.: for key,obj in
> dict:
>   obj.name = key
> ___ Tutor maillist  - 
> Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Are you looking for dir() (built-in function)

dir() -> returns names in current scope
dir(module/class/object) -> module/class/object's attributes

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get a module's own (top_level) dict?

2008-11-09 Thread Kent Johnson
On Sun, Nov 9, 2008 at 5:34 AM, spir <[EMAIL PROTECTED]> wrote:
> Hello pyhonistas,
>
> Example:
> === module content ===
> a = 1
> b = 2
> ==
>
> I'm looking for a way to get something like {'a':a, b':2}. Actually, names
> defind in the module will be instances of a custom type. I want to give them
> an attribute that holds their own name. E.g.:
> for key,obj in dict:
>obj.name = key

>From within the module, globals() returns the dict you want. However I
would say that needing to know the name of something is a code smell.
The usual way to do this is to keep an explicit dict of the objects of
interest.

Why do you need objects to know their name? Why can't you tell it it's
name when you create it?

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question

2008-11-09 Thread Rich Lovely
All you really need for python is a basic text editor, and the  
interpretter. Everything else is icing. Notepad++ has syntax  
highlighting support for python, and sounds as if it has brace and  
bracket completion. Most people here will tell you that auto- 
completion in python is a complex issue (most objects can have dynamic  
attributes defined at runtime that most auto-complete engines will  
miss). Notepad++ also supports auto-indentation, which is probably the  
most useful feature of any editor used for python.


Note I've never used it myself, just took a quick look through it's  
website.


---
Richard "Roadie Rich" Lovely
Part of the JNP|UK Famille
www.theJNP.com

(Sent from my iPod - please allow me a few typos: it's a very small  
keyboard)


On 9 Nov 2008, at 03:22 AM, Bap <[EMAIL PROTECTED]> wrote:


Can I use notepad++ for Python?

Thank you! ;-)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi scripts

2008-11-09 Thread Tim Johnson
On Saturday 08 November 2008, Kent Johnson wrote:
> On Sat, Nov 8, 2008 at 3:38 AM, Jim Morcombe <[EMAIL PROTECTED]> 
wrote:
> > I think the problem wasn't in getting the keys and values, but I might
> > have been producing illegal HTML code before.
> > I think I'd better brush up on my HTML skills.
>
> Poorly formed HTML won't give an internal server error. That is due to
> something more serious such as a syntax error in your program.
   I always configure cgi scripts so that I can also run them from the command
   line. That can be an effective way to catch errors otherwise obfuscated
   by the browser. Although I don't use windows any longer, I recall that
   pythonwin was a nice IDE to use and it probably has a syntax checker.
tim



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get a module's own (top_level) dict?

2008-11-09 Thread Kent Johnson
On Sun, Nov 9, 2008 at 3:42 PM, spir <[EMAIL PROTECTED]> wrote:
> Thank you Lie & Kent, that's it. Excuse me, Lie, I answered too fast.
> Now, to answer Kent questions, there are several reasons why I wish to do
> that.
> These objects will be of a 'pattern' type that (unlike function, for
> instance), don't know how they're called. They need to hold their name to
> pass it to further objects (say, tokens) that will be generated according to
> these patterns, but who are not instances of the patterns. Actually, the
> pattern's name is a kind of token 'type'. You see what I mean?

No, not at all. Why can't you assign the pattern's name when you create it?

> Concretely, I need to instanciate object with a type specified by the
> pattern's name and init data given by the result of the parsing.

This can be done with a dict mapping pattern names to types. I don't
see how having a pattern know its own name helps here.

For example:
In [22]: class Foo:
   : def __init__(self, x):
   : print "Foo(%s)" % x

In [24]: class Bar:
   : def __init__(self, x):
   : print "Bar(%s)" % x

In [25]: types = dict(foo=Foo, bar=Bar)

In [26]: types['foo'](3)
Foo(3)

In [27]: types['bar'](42)
Bar(42)

> Also, I want to write the pattern --> name --> type --> object toolset in a
> general to be able to reuse it. Also, simply because I want it so!
> There will be many such names, too.
> Also: the patterns will actually be generated at runtime according to a
> config file -- and can also change at runtime (--> reload() grammar module),
> following user customization. So that I don't even know the names at design
> time.

How are you going to create all these named objects?

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor