Re: [Tutor] accessing another system's environment

2011-02-25 Thread Bill Allen
On Fri, Feb 25, 2011 at 22:39, Steve Willoughby  wrote:

>
> One question you need to figure out is how interactive you want this to be,
> or how automated.  That will drive the implementation of what comes after.
>  As will the list of available options at your site for securely allowing a
> remote host to run administrative tools on your windows systems.
>
>
> I am pretty basic and no-frills about programs, particularly ones that are
utilities for my own use.   I am one of those admins that has full
administrator privs on the site workstations, so I am able to run anything I
like on or against these systems.   I am envisioning a little command line
program that would work like this:

$python get_set_env.py -c some_computer_name
This would then just dump the system environment variables of
some_computer_name

$python get_set_env.py -c some_computer_name -e UG_SHOW_MOD True
On the system some_computer_name, this would edit the system environment
variable UG_SHOW_MOD to a value of True.

$python get_set_env.py -c some_computer_name -s UG_RUN_DIR  C:\UGII
On the system some_computer_name, this would create the system environment
variable UG_RUN_DIR and set it to the value C:\UGII

--Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cross-Module Interaction

2011-02-25 Thread Corey Richardson
On 02/26/2011 12:11 AM, Steven D'Aprano wrote:
> [steve@sylar ~]$ python
> Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
> [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import lib
>  >>> import a
>  >>> lib.g
> []
>  >>> a.do_stuff()
>  >>> lib.g
> [42]
> 
> 
> Of course, when your application exists (or in this case, the 
> interactive session), the changes to lib.g will be lost because they 
> only exist in memory. If you want data to persist across application 
> runs, you need to arrange for the application to save the data to disk, 
> and then read it again when it starts up.

Aha, that explains why I didn't get any results. Each file got its own
interpreter instance.

> 
> Python has many tools for working with persistent data: Windows-style 
> ini files (module config parser), XML, JSON, Mac-style plists, YAML 
> (third-party module only), and pickles, to name only a few.

In any case everything would be called in one interpreter, which I
didn't know worked because I didn't test it like you showed it, but to
be safe I definitely need to persist that data every once in a while.

I'm slightly concerned about performance when it comes to
reading/writing to disk a lot when doing things like that, since if this
thing ever needs to scale I want it to be able to do that.

Thank you, Steven
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cross-Module Interaction

2011-02-25 Thread Steven D'Aprano

Corey Richardson wrote:


My first thought was to have a module specifically for holding things
like that, global objects that all the interacting modules need access
to. I did a simple test with a lib module, and then a few modules that
simply added things to a list called g in that lib module, but the
changes did not persist (tested with another module that printed the
contents of lib.g)


Perhaps you should give a *simple* example, but what you describe should 
work. Let's start with a very simple library module:


# lib.py
g = []


Now let's import it and use it from another module:

# a.py
import lib

def do_stuff():
lib.g.append(42)


Save those two files as named, and then import them into the interactive 
interpreter:



[steve@sylar ~]$ python
Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lib
>>> import a
>>> lib.g
[]
>>> a.do_stuff()
>>> lib.g
[42]


Of course, when your application exists (or in this case, the 
interactive session), the changes to lib.g will be lost because they 
only exist in memory. If you want data to persist across application 
runs, you need to arrange for the application to save the data to disk, 
and then read it again when it starts up.


Python has many tools for working with persistent data: Windows-style 
ini files (module config parser), XML, JSON, Mac-style plists, YAML 
(third-party module only), and pickles, to name only a few.




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Steve Willoughby

On 25-Feb-11 20:26, Bill Allen wrote:



On Fri, Feb 25, 2011 at 21:33, Steve Willoughby mailto:st...@alchemy.com>> wrote:

On 25-Feb-11 19:27, Steve Willoughby wrote:


Or are you saying you want to, from a remote Unix system, reach out
to a Windows system and see that Windows system's system environment
variables?


Yes, that's it exactly.:-)


Ok... this is starting to make more sense then.

So you have two problems, really.  One is to get the linux box to invoke 
a command remotely on the windows box, and the other is what command to 
run on the windows side.  Either *could* be a Python script, in theory, 
but those are two separate problems.


There are lots of ways to go about this.  You could write some kind of 
service in Python (CPython, or IronPython/.net or even C# or whatever) 
which manages the settings on your windows system. A Python script could 
then be written to interact with that service.


Or, you could use a linux RDP-compatible tool to interactively run 
commands on the windows box for you.


One question you need to figure out is how interactive you want this to 
be, or how automated.  That will drive the implementation of what comes 
after.  As will the list of available options at your site for securely 
allowing a remote host to run administrative tools on your windows systems.



I administrate the workstations in our engineering environment and some
of the major pieces of software we use are configured via the Windows
system environment variables.  Being able to reach out to a PC and check
or change those is handy, even important, in my situation.   I am trying
to explore the possibility of managing these from a system I am using in
a platform independent way and figure that I ought to be able to do this
with Python.  Perhaps there are third party Python modules I need to
help accomplish this?

--Bill




--
Steve Willoughby / st...@alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cross-Module Interaction

2011-02-25 Thread Corey Richardson
Greetings, Tutors

(Sorry for the poor subject name, couldn't think of anything better)

I'm writing a MUD server as part of a school project. Yes this is
homework, but I'm not taking a traditional programming class (going
through the OCW for CS50 at Harvard and getting credit).

I'm in the design phase and am testing out a few things. One thing I
will definitely need is a global players_online collection which will
act much like the name implies.

My first thought was to have a module specifically for holding things
like that, global objects that all the interacting modules need access
to. I did a simple test with a lib module, and then a few modules that
simply added things to a list called g in that lib module, but the
changes did not persist (tested with another module that printed the
contents of lib.g)

I'm probably thinking about this from the wrong direction. Is there
something about this approach that I'm missing, or is there a different
way I should be using?

(If you're curious about the telephone data-transfer I was working on, I
ran into too much trouble with the various sound libraries that exist to
wrap over Alsa or JACK, so I put it off for the future after I'm more
comfortable with C/C++)
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Bill Allen
On Fri, Feb 25, 2011 at 21:33, Steve Willoughby  wrote:

> On 25-Feb-11 19:27, Steve Willoughby wrote:
>
>
> Or are you saying you want to, from a remote Unix system, reach out to a
> Windows system and see that Windows system's system environment variables?


Yes, that's it exactly.:-)

I administrate the workstations in our engineering environment and some of
the major pieces of software we use are configured via the Windows system
environment variables.  Being able to reach out to a PC and check or change
those is handy, even important, in my situation.   I am trying to explore
the possibility of managing these from a system I am using in a platform
independent way and figure that I ought to be able to do this with Python.
Perhaps there are third party Python modules I need to help accomplish this?

--Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Steve Willoughby

On 25-Feb-11 19:27, Steve Willoughby wrote:

Wait.

Are you trying to figure out how, on a Unix system, to read Unix system 
environment variables as you're accustomed to doing on Windows?


Or are you saying you want to, from a remote Unix system, reach out to a 
Windows system and see that Windows system's system environment variables?




On 25-Feb-11 18:50, Bill Allen wrote:

I apologize for not have been clear previously. What I am trying to
access are the Windows system environment variables. The same ones
that are listed out if you type the set command at a command prompt in
Windows.


There isn't a "system" set of environment variables on Unix-like
systems--there is a default "starting" set per user (although they are
configurable per-process as has already been stated).

Perhaps you want to see the set of variables for the "root" account? But
again, I have to ask what you're really trying to accomplish.
Environment variables are only such a small part of a system's
configuration, on Windows or Unix/Linux. On a Windows box, I would
probably be more interested in what's in the system registry, for
example, and on a Unix system I'd want to see what's in various
configuration files in /etc to know what's configured on that system.

Environment variables, from the point of view of a random process
running on the system, are pretty much the same on both Windows and
Unix. Where they come from, and which are "system" or "user" variables,
is quite different, and I suspect you're reaching for environment
variables out of habit but that may not ultimately be what you're really
looking for here.

Or maybe it is. If it is, step back and consider WHOSE set of variables
you really want? The root account? the account of a service that you're
interested in? The default skeleton configuration files for new users?
The environment of something you know to be running already?

All of those things are possible to look at, if you know what you're
really after and why it will help you accomplish what you need to do.

--steve




--Bill





On Fri, Feb 25, 2011 at 03:11, Alan Gauld mailto:alan.ga...@btinternet.com>> wrote:


"Bill Allen" mailto:walle...@gmail.com>> wrote

I have times when it is useful for me to check the environment
of a user
system on our lan remotely while trouble shooting and issue with
them. Now,
this is quite easy to do while I am using a windows system via
the computer
management console.


I think we are meaning different things by "environment"?
Can you give a specific example?


However, I am trying to do this via a linux workstation
(which is joined to the domain, etc.). I cannot find a native
facility to duplicate the computer management functions, so I
thought I
would write a program to fill the need.


Anything you can do locally you can do on the remote
machine with a combination of ssh, rsh, rlogin, telnet etc.
ssh is the safest but requires a bit more admin to set it
up properly for maximum convenience.

Having got remote access its just a case of figuring out
which of the 500 or so Unix commands you need to
use to do the job... :-)


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist - Tutor@python.org 
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor






--
Steve Willoughby / st...@alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Steve Willoughby

On 25-Feb-11 18:50, Bill Allen wrote:

I apologize for not have been clear previously.   What I am trying to
access are the Windows system environment variables.   The same ones
that are listed out if you type the set command at a command prompt in
Windows.


There isn't a "system" set of environment variables on Unix-like 
systems--there is a default "starting" set per user (although they are 
configurable per-process as has already been stated).


Perhaps you want to see the set of variables for the "root" account? 
But again, I have to ask what you're really trying to accomplish. 
Environment variables are only such a small part of a system's 
configuration, on Windows or Unix/Linux.  On a Windows box, I would 
probably be more interested in what's in the system registry, for 
example, and on a Unix system I'd want to see what's in various 
configuration files in /etc to know what's configured on that system.


Environment variables, from the point of view of a random process 
running on the system, are pretty much the same on both Windows and 
Unix.  Where they come from, and which are "system" or "user" variables, 
is quite different, and I suspect you're reaching for environment 
variables out of habit but that may not ultimately be what you're really 
looking for here.


Or maybe it is.  If it is, step back and consider WHOSE set of variables 
you really want?  The root account? the account of a service that you're 
interested in? The default skeleton configuration files for new users? 
The environment of something you know to be running already?


All of those things are possible to look at, if you know what you're 
really after and why it will help you accomplish what you need to do.


--steve




--Bill





On Fri, Feb 25, 2011 at 03:11, Alan Gauld mailto:alan.ga...@btinternet.com>> wrote:


"Bill Allen" mailto:walle...@gmail.com>> wrote

I have times when it is useful for me to check the environment
of a user
system on our lan remotely while trouble shooting and issue with
them.  Now,
this is quite easy to do while I am using a windows system via
the computer
management console.


I think we are meaning different things by "environment"?
Can you give a specific example?


However, I am trying to do this via a linux workstation
(which is joined to the domain, etc.).   I cannot find a native
facility to duplicate the computer management functions, so I
thought I
would write a program to fill the need.


Anything you can do locally you can do on the remote
machine with a combination of ssh, rsh, rlogin, telnet etc.
ssh is the safest but requires a bit more admin to set it
up properly for maximum convenience.

Having got remote access its just a case of figuring out
which of the 500 or so Unix commands you need to
use to do the job... :-)


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  - Tutor@python.org 
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



--
Steve Willoughby / st...@alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Bill Allen
I apologize for not have been clear previously.   What I am trying to access
are the Windows system environment variables.   The same ones that are
listed out if you type the set command at a command prompt in Windows.


--Bill





On Fri, Feb 25, 2011 at 03:11, Alan Gauld  wrote:

>
> "Bill Allen"  wrote
>
>  I have times when it is useful for me to check the environment of a user
>> system on our lan remotely while trouble shooting and issue with them.
>>  Now,
>> this is quite easy to do while I am using a windows system via the
>> computer
>> management console.
>>
>
> I think we are meaning different things by "environment"?
> Can you give a specific example?
>
>
>  However, I am trying to do this via a linux workstation
>> (which is joined to the domain, etc.).   I cannot find a native
>> facility to duplicate the computer management functions, so I thought I
>> would write a program to fill the need.
>>
>
> Anything you can do locally you can do on the remote
> machine with a combination of ssh, rsh, rlogin, telnet etc.
> ssh is the safest but requires a bit more admin to set it
> up properly for maximum convenience.
>
> Having got remote access its just a case of figuring out
> which of the 500 or so Unix commands you need to
> use to do the job... :-)
>
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list of dictionary

2011-02-25 Thread Pacific Morrowind



On 25/02/2011 9:44 AM, Patty wrote:


- Original Message -
*From:* Pacific Morrowind 
*To:* tutor@python.org 
*Sent:* Thursday, February 24, 2011 10:21 PM
*Subject:* Re: [Tutor] list of dictionary

Presuming you do have to use the dictionaries:
qty = 0.0
for item in d:

Right here - is the variable 'item' created right on the spot to
iterate over this list?  And I think you are doing the same thing
when you create the variable 'subitem' in the line below, right? 
I am  trying to get myself to recognize an iterator variable as

opposed to a counter variable I create myself  to keep track of
these things (used in other programming languages) - and realizing
the difference between counter/iterator variables and variables
that I really care about like
 'd = []' .
Thanks!
Patty

yes and yes. both item and subitem are created on the spot; anychunk of 
python code like:

for x in y:
will create x as a variable and with each iteration x refers to the next 
item in y;
Of course if I knew the function of the list/dictionary I'd name them 
something more informative than item and subitem - like f.e. for lap in 
d and for time in d if it was refering to races.

Nick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] scripts search

2011-02-25 Thread Alan Gauld


"Victor Binns"  wrote

I have a small business and I wanted to use python 
in my business.  I have a need for an 
Employee Time and Attendance software.



Is there any python scripts out there that can do the trick?


I'm not aware of any but a Google or Sourceforge search 
might throw up something.


However depending how small your business is you 
might find spreadsheets are sufficient for your needs 
and much easier to set up than trying to write 
something from scratch in Python...


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Existing Python

2011-02-25 Thread Alan Gauld


"Justin Bonnell"  wrote

Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin

Type "copyright", "credits" or "license()" for more information.




The >>> prompt means you are already inside Python.
You can type Python commands at the >>> prompt, things like


print "Hello"


But you cannot ruin a program from inside the >>> prompt 
(well, you can, but its more complicated than sane people 
want to bother with! :-)


You run a Python script from the OS Terminal prompt:

$ python hello.py


Shouldn't I be able to run hello.py from the IDLE interpreter?


You can't run it from the >>> prompt in IDLE but
What you can do is open the file for editing and then 
run that file using the menu commands, then the 
output will show up in the interpreter window.


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] scripts search

2011-02-25 Thread Corey Richardson
On 02/25/2011 03:20 PM, Victor Binns wrote:
> 
> Hello I am fairly new to python.
>  
> I have a small business and I wanted to use python in my business.  I have a 
> need for an 
> Employee Time and Attendance software.
>  
> Is there any python scripts out there that can do the trick?
>  

I don't know of any and a google didn't return favorable results. You'll
have to write it yourself. Luckily, Python is one of the more simple
languages and you should have a fairly easy time writing it.

Check out http://www.alan-g.me.uk/tutor/index.htm if you haven't
programmed before, and if you have, try this:
http://docs.python.org/tutorial/

-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] scripts search

2011-02-25 Thread Victor Binns

Hello I am fairly new to python.
 
I have a small business and I wanted to use python in my business.  I have a 
need for an 
Employee Time and Attendance software.
 
Is there any python scripts out there that can do the trick?
 
Victor
 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Search function in a list-tuples

2011-02-25 Thread ALAN GAULD
CCing group. Please use ReplyAll in replies to the list.

 > Hi, thank your for your answer. i wrote this now :


>def HeroExist(HerosName):
>for heros in herosAll:
>if HerosName in heros.name:
>herosId = heros.id
>return herosId
>return None
>
>HerosName=input("Enter heros name : ")
>ch = HeroExist(HerosName)
>if ch:  
>ch.DisplayCharacterInfos()
>else :
>print ('This heros does\'nt exist')
>
>But whatever i type, he says : heros doesn't exist :/
>
>That suggets a problem with how the name is being stored.
Can you send the code for the Character class, esp[ecially the init method.
Plus a cut n paste of the output of a ruin of the programme so that 
we can see exactly what you are inputting and what the 
results are? 

BTW you don't need the \ in the last print. You are using double quotes 
around the string so you can just type the single quote directly

print ( "This hero doesn't exist')

Alan G.


2011/2/25 Alan Gauld 
>
>"Christopher Brookes"  wrote
>>
>>
>>Hi, is there a better way to do this ? (*heros are Character*)
>>>
>There are several better ways but mainly they involve
>techniques that may be too advanced for you at present,
>so we'll keep it simple for now :-)
>
>
>
>herosAll = [
>>Character(0,"Chris","Soldat fort",type[0],15,5,8,50,1),
>>Character(1,"Antaa","Soldat moins fort",type[0],15,5,8,50,1)]
>>
>>def HeroExist(HerosName):
>>  herosId = -1
>>  for heros in herosAll:
>>  if HerosName in heros.name:
>>  herosId = heros.id
>>  if herosId != -1:
>>  return herosId
>>  else:
>>  return -1
>>

replace from the for loop down with:
>
>
>  for heros in herosAll:
>  if HerosName in heros.name:
>  herosId = heros.id
>
  return herosId
>  return None   # This allows more convenient testing, see below
>
>Which has the advantage of being slightly faster too.
>
>
>
>  HerosName=input("Enter heros name : ")
>>  if Character.HeroExist(HerosName) != -1:
>>

HeroExist is not a method of Character ( although you could
>make it so - one of the better solutions I alluded to above! )
>So you don't need to prefix it with Character.
>
>And you can assign the return value to a variable so
>you avoid calling it twice:
>
>
>  HerosName=input("Enter heros name : ")
>
  ch = HeroExist(HerosName):
>  if ch:   # because None is treated as False
>  ch.DisplayCharacterInfos()
>
>  else :
>  print ('This heros does\'nt exist')
>
>
HTH,
>
>
>-- 
>Alan Gauld
>Author of the Learn to Program web site
>http://www.alan-g.me.uk/
>
>
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>-- 
>Brookes Christopher.
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Existing Python

2011-02-25 Thread Corey Richardson
On 02/25/2011 06:42 PM, Justin Bonnell wrote:
> I downloaded Python 2.7.1. I think this is a pretty basic question.
> When I try to run the existing python files on the computer (hello.py), I 
> receive a syntax error. 
> 
> Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
> [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
> Type "copyright", "credits" or "license()" for more information.
 python hello.py
> SyntaxError: invalid syntax
> 
> I am running Mac OS X version 10.6.6.
> Shouldn't I be able to run hello.py from the IDLE interpreter?

You need to run "python hello.py" in a terminal window, not from the
Python interpreter. If you are using IDLE, you can File > Open hello.py
and hit F5 to run it... I don't know if that advice applies to Mac,
might be different key strokes.

-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Running Existing Python

2011-02-25 Thread Justin Bonnell
I downloaded Python 2.7.1. I think this is a pretty basic question.
When I try to run the existing python files on the computer (hello.py), I 
receive a syntax error. 

Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> python hello.py
SyntaxError: invalid syntax

I am running Mac OS X version 10.6.6.
Shouldn't I be able to run hello.py from the IDLE interpreter?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python in MATLAB

2011-02-25 Thread Sriram Jaju
I googled but i didn't get considerable results.
I am doing a project on optical character recognition, i tried a code on
matlab, but it was not efficient.
I tried it on python it worked. Now i want to embed python code in matlab
code with other matlab function such as image acquisition etc.
so how it can be done?

On Fri, Feb 25, 2011 at 11:48 PM, Chris Fuller <
cfuller...@thinkingplanet.net> wrote:

>
> Absolutely.  You can use mex files to interface with the Python API (this
> requires considerable C proficiency), or you can use something like pymex
> or

pymat.  Did you google "matlab python"?
>
> http://vader.cse.lehigh.edu/~perkins/pymex.html
> http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html
>
> Cheers
>
> On Friday 25 February 2011, Sriram Jaju wrote:
> > can i embed python code in MATLAB program?
>
>


-- 
Xcited 2 be AliveSriram
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Search function in a list-tuples

2011-02-25 Thread Christopher Brookes
Hi,

I found the solution :)

Special thanks to Alan G.

Solution :

def FindByName(HerosName):
for heros in herosAll:
if HerosName == heros.name:
return heros
return None

HerosName = 'notfound'
while FindByName(HerosName) == None:
HerosName=input("Enter heros name (type exit for close): ")
if HerosName.lower() == 'exit':
Display_menu()
else:
ch = FindByName(HerosName)
if ch:
ch.DisplayCharacterInfos()
newSearch=input('New search ? (Y/N)')

else :
print ('This heros does\'nt exist')


2011/2/25 ALAN GAULD 

> CCing group. Please use ReplyAll in replies to the list.
>
>
> > Hi, thank your for your answer. i wrote this now :
>
>
> def HeroExist(HerosName):
> for heros in herosAll:
> if HerosName in heros.name:
> herosId = heros.id
> return herosId
> return None
>
> HerosName=input("Enter heros name : ")
> ch = HeroExist(HerosName)
> if ch:
> ch.DisplayCharacterInfos()
> else :
> print ('This heros does\'nt exist')
>
> But whatever i type, he says : heros doesn't exist :/
>
> That suggets a problem with how the name is being stored.
> Can you send the code for the Character class, esp[ecially the init method.
> Plus a cut n paste of the output of a ruin of the programme so that
> we can see exactly what you are inputting and what the
> results are?
>
> BTW you don't need the \ in the last print. You are using double quotes
> around the string so you can just type the single quote directly
>
> print ( "This hero doesn't exist')
>
> Alan G.
>
> 2011/2/25 Alan Gauld 
>
>> "Christopher Brookes"  wrote
>>
>>  Hi, is there a better way to do this ? (*heros are Character*)
>>>
>>
>> There are several better ways but mainly they involve
>> techniques that may be too advanced for you at present,
>> so we'll keep it simple for now :-)
>>
>>
>>  herosAll = [
>>> Character(0,"Chris","Soldat fort",type[0],15,5,8,50,1),
>>> Character(1,"Antaa","Soldat moins fort",type[0],15,5,8,50,1)]
>>>
>>> def HeroExist(HerosName):
>>>   herosId = -1
>>>   for heros in herosAll:
>>>   if HerosName in heros.name:
>>>   herosId = heros.id
>>>   if herosId != -1:
>>>   return herosId
>>>   else:
>>>   return -1
>>>
>>
>> replace from the for loop down with:
>>
>>
>>   for heros in herosAll:
>>   if HerosName in heros.name:
>>   herosId = heros.id
>>   return herosId
>>   return None   # This allows more convenient testing, see below
>>
>> Which has the advantage of being slightly faster too.
>>
>>
>>HerosName=input("Enter heros name : ")
>>>   if Character.HeroExist(HerosName) != -1:
>>>
>>
>> HeroExist is not a method of Character ( although you could
>> make it so - one of the better solutions I alluded to above! )
>> So you don't need to prefix it with Character.
>>
>> And you can assign the return value to a variable so
>> you avoid calling it twice:
>>
>>
>>   HerosName=input("Enter heros name : ")
>>   ch = HeroExist(HerosName):
>>   if ch:   # because None is treated as False
>>   ch.DisplayCharacterInfos()
>>
>>   else :
>>   print ('This heros does\'nt exist')
>>
>> HTH,
>>
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Brookes Christopher.
>
>


-- 
Brookes Christopher.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python in MATLAB

2011-02-25 Thread Chris Fuller

Absolutely.  You can use mex files to interface with the Python API (this 
requires considerable C proficiency), or you can use something like pymex or 
pymat.  Did you google "matlab python"?

http://vader.cse.lehigh.edu/~perkins/pymex.html
http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html

Cheers

On Friday 25 February 2011, Sriram Jaju wrote:
> can i embed python code in MATLAB program?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list of dictionary

2011-02-25 Thread Patty

  - Original Message - 
  From: Pacific Morrowind 
  To: tutor@python.org 
  Sent: Thursday, February 24, 2011 10:21 PM
  Subject: Re: [Tutor] list of dictionary


  Hi;

  On 24/02/2011 9:35 PM, sunil tech wrote: 
Hi all...

i have d=[{'qty':0.0},{'qty':0.0}



  If there isn't some pressing reason to dictionaries as the list items (but 
since I'm not sure how you're generating the list/what you are later using the 
list I can't tell ofc but 

  Hi - I had just a couple comments plus clarification about lists and 
iterating:  

  if applicable to your situation I'd suggest just doing for creation of the 
list
   d = []

  I like creating the empty variable structure, makes the code really clear. 

  (logic for whatever gives your values)
  d.append(value)
  etc.)

when all the qty is 0.0,
i want to perform some print operation
(only at once, after it checks everything in the list of dictionary 'd')...

if its not 0.0,
print some message...

Thank you in advance

  Presuming you do have to use the dictionaries:
  qty = 0.0
  for item in d:

  Right here - is the variable 'item' created right on the spot to iterate over 
this list?  And I think you are doing the same thing when you create the 
variable 'subitem' in the line below, right?  I am  trying to get myself to 
recognize an iterator variable as opposed to a counter variable I create myself 
 to keep track of these things (used in other programming languages) - and 
realizing the difference between counter/iterator variables and variables that 
I really care about like 
   'd = []' .

  Thanks!

  Patty


  for subitem in d:
  if item[subitem] != 0.0:
  qty = item[subitem]
  break
  if qty != 0.0:
  print "some message - for example a non zero qty = %f" % qty

  (presuming you are using Python 2x - if using python 3x the syntax will be 
slightly different)
  Hopefully that will serve your purpose if not just post again and I or one of 
the more frequently posting helpful users here will answer soon.
  Nick




--


  ___
  Tutor maillist  -  Tutor@python.org
  To unsubscribe or change subscription options:
  http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to vectorize a constant function?

2011-02-25 Thread Peter Otten
Jose Amoreira wrote:

> I am trying to define a constant vectorized function, that is, one that
> returns 1. (for instance) when called with a scalar argument x and that
> returns array([1.,1.,1.]) when the argument is a three-element array, etc.

With the help of google I found

http://docs.scipy.org/doc/numpy/reference/generated/numpy.frompyfunc.html

>>> import numpy
>>> def f(x): return 42
...
>>> f = numpy.frompyfunc(f, 1, 1)
>>> f(1)
42
>>> f(numpy.zeros(7))
array([42, 42, 42, 42, 42, 42, 42], dtype=object)


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Search function in a list-tuples

2011-02-25 Thread Alan Gauld

"Christopher Brookes"  wrote


Hi, is there a better way to do this ? (*heros are Character*)


There are several better ways but mainly they involve
techniques that may be too advanced for you at present,
so we'll keep it simple for now :-)


herosAll = [
Character(0,"Chris","Soldat fort",type[0],15,5,8,50,1),
Character(1,"Antaa","Soldat moins fort",type[0],15,5,8,50,1)]

def HeroExist(HerosName):
   herosId = -1
   for heros in herosAll:
   if HerosName in heros.name:
   herosId = heros.id
   if herosId != -1:
   return herosId
   else:
   return -1


replace from the for loop down with:

   for heros in herosAll:
   if HerosName in heros.name:
   herosId = heros.id
   return herosId
   return None   # This allows more convenient testing, see below

Which has the advantage of being slightly faster too.


   HerosName=input("Enter heros name : ")
   if Character.HeroExist(HerosName) != -1:


HeroExist is not a method of Character ( although you could
make it so - one of the better solutions I alluded to above! )
So you don't need to prefix it with Character.

And you can assign the return value to a variable so
you avoid calling it twice:

   HerosName=input("Enter heros name : ")
   ch = HeroExist(HerosName):
   if ch:   # because None is treated as False
   ch.DisplayCharacterInfos()
   else :
   print ('This heros does\'nt exist')

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to vectorize a constant function?

2011-02-25 Thread Jose Amoreira
Hello!
In "A Primer on Scientific Programming with Python", they define a vectorized 
function as a scalar function that, when called with a vector argument, 
returns a vector with the values of the function for each of the values stored 
in the argument vector.

I am trying to define a constant vectorized function, that is, one that 
returns 1. (for instance) when called with a scalar argument x and that 
returns array([1.,1.,1.]) when the argument is a three-element array, etc.

Here are a few snippets of an interactive session displaying my failed 
attempts:
---
In [1]: from numpy import *
In [2]: def f(x):
   ...: return 1.
In [3]: x=linspace(0,1,5)
In [4]: print f(x)
--> print(f(x))
1.0
-
That's not what I want, that's a scalar, not a five element array. Next 
option:
-
In [13]: def g(x):
   : return where(True,1.,0.)
In [14]: print g(x)
---> print(g(x))
1.0
---
Still not right. But here is something strange. The values in x are non-
negative, therefore the test x>=0 yelds True for each element in x. One might 
then think that g(x) as defined above would, in this case, be equivalent to 
h(x) defined below:
--
In [16]: def h(x):
   : return where(x>=0,1.,0)
---
However,
---
In [18]: print h(x)
---> print(h(x))
[ 1.  1.  1.  1.  1.]
---
So my questions are:
1. What's the proper way to vectorize a constant function (I know that we 
really don't have to, but I'd like to do it in a first step towards a more 
sophisticated calculation)?
2. Why do g(x) and h(x) return different results?
3. Why doesn't f(x) work?
Thanks
Jose
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python in MATLAB

2011-02-25 Thread Sriram Jaju
can i embed python code in MATLAB program?



-- 
Xcited 2 be AliveSriram
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python in MATLAB

2011-02-25 Thread Sriram Jaju
can i embed python code in MATLAB program?

-- 
Xcited 2 be AliveSriram
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unintentionally manipulating a list

2011-02-25 Thread Steven D'Aprano

ranjan das wrote:

I am facing the following problem


I have a list of the form

INPUT= [ [ ['A1-N','A2-Y','A3-N' ],['B1-Y','B2-N','B3-N' ] ], [.] ]



and I want an output of the form (selecting only those elements which have a
Y associated with them)

OUTPUT=[ ['A2-Y', 'B1-Y'],[] ]


Can the Y be anywhere, or must it be at the end of the string? Should 
'Y2-N' be included or excluded? I will assume excluded.


What about lowercase 'y'? Should 'A3-y' be included? I assume it should be.




I wrote the following code. Although it gives me the desired output, it
CHANGES the list INPUT


Start with a simple function that extracts the strings you want from the 
inner-most list, Here's the hard way:


def select(items, suffix):
suffix = suffix.upper()
result = []
for s in items:
if s.upper().endswith(suffix):
result.append(s)
return result


This can be simplified to:

def select(items, suffix):
suffix = suffix.upper()
return [s for s in items if s.upper().endswith(suffix)]


Now you can use it:



OUTPUT = []
# INPUT looks like:
# [ [a1_list, b1_list, ...], [a2_list, b2_list, ...], ... ]
for middle in INPUT:
# middle looks like [a99_list, b99_list, c99_list, ...]
temp = []
for inner in middle:
# inner looks like [astr-N, bstr-Y, cstr-Y, ...]
temp.extend(select(inner, '-Y'))
OUTPUT.append(temp)


There is no need to make a copy of the input list.



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unintentionally manipulating a list

2011-02-25 Thread Knacktus

Am 25.02.2011 15:49, schrieb ranjan das:


I am facing the following problem


I have a list of the form

INPUT= [ [ ['A1-N','A2-Y','A3-N' ],['B1-Y','B2-N','B3-N' ] ], [.] ]


and I want an output of the form (selecting only those elements which
have a Y associated with them)

OUTPUT=[ ['A2-Y', 'B1-Y'],[] ]


I wrote the following code. Although it gives me the desired output, it
CHANGES the list INPUT

now after i run the code I get INPUT as the same as OUTPUT (which i dont
want to happen). I have used the copy function but it still is not
working. Any help or pointers is appreciated

_CODE_

from copy import copy

temp=copy( INPUT )
OUTPUT=temp



for i in range(len(temp)):

 for j in range(len(temp[i])):

 for k in range(len(temp[i][j])):

 if temp[i][j][k][-1]=='Y':

 OUTPUT[i][j]=temp[i][j][k]


There's no need for an index. You can iterate over the elements directly 
and create the result on the fly:


results = []
for sub_list in INPUT:
sub_results = []
for sub_sub_list in sub_list:
sub_sub_results = []
for entry in sub_sub_list:
if entry.endswith("Y"):
sub_sub_results.append(entry)
if sub_sub_results:
sub_results.append(sub_sub_results)
if sub_results:
results.append(sub_results)

Uuppsy daisy, not really readable code ;-). Your solution looks cleaner. 
I bet, some of the gurus can come up with a real pythonic solution.


Cheers,

Jan








___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unintentionally manipulating a list

2011-02-25 Thread Alex Hall
You may want to deepcopy instead of just copy?

On 2/25/11, ranjan das  wrote:
> I am facing the following problem
>
>
> I have a list of the form
>
> INPUT= [ [ ['A1-N','A2-Y','A3-N' ],['B1-Y','B2-N','B3-N' ] ], [.] ]
>
>
> and I want an output of the form (selecting only those elements which have a
> Y associated with them)
>
> OUTPUT=[ ['A2-Y', 'B1-Y'],[] ]
>
>
> I wrote the following code. Although it gives me the desired output, it
> CHANGES the list INPUT
>
> now after i run the code I get INPUT as the same as OUTPUT (which i dont
> want to happen). I have used the copy function but it still is not working.
> Any help or pointers is appreciated
>
> *CODE*
>
> from copy import copy
>
> temp=copy( INPUT )
> OUTPUT=temp
>
>
>
> for i in range(len(temp)):
>
> for j in range(len(temp[i])):
>
> for k in range(len(temp[i][j])):
>
> if temp[i][j][k][-1]=='Y':
>
> OUTPUT[i][j]=temp[i][j][k]
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unintentionally manipulating a list

2011-02-25 Thread ranjan das
I am facing the following problem


I have a list of the form

INPUT= [ [ ['A1-N','A2-Y','A3-N' ],['B1-Y','B2-N','B3-N' ] ], [.] ]


and I want an output of the form (selecting only those elements which have a
Y associated with them)

OUTPUT=[ ['A2-Y', 'B1-Y'],[] ]


I wrote the following code. Although it gives me the desired output, it
CHANGES the list INPUT

now after i run the code I get INPUT as the same as OUTPUT (which i dont
want to happen). I have used the copy function but it still is not working.
Any help or pointers is appreciated

*CODE*

from copy import copy

temp=copy( INPUT )
OUTPUT=temp



for i in range(len(temp)):

for j in range(len(temp[i])):

for k in range(len(temp[i][j])):

if temp[i][j][k][-1]=='Y':

OUTPUT[i][j]=temp[i][j][k]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Search function in a list-tuples

2011-02-25 Thread Christopher Brookes
Hi, is there a better way to do this ? (*heros are Character*)

herosAll = [
Character(0,"Chris","Soldat fort",type[0],15,5,8,50,1),
Character(1,"Antaa","Soldat moins fort",type[0],15,5,8,50,1)]


def HeroExist(HerosName):
herosId = -1
for heros in herosAll:
if HerosName in heros.name:
herosId = heros.id
if herosId != -1:
return herosId
else:
return -1

I find this solution myself and I think a better one exist..

HerosName=input("Enter heros name : ")
if Character.HeroExist(HerosName) != -1:

herosAll[Character.HeroExist(HerosName)].DisplayCharacterInfos()
else :
print ('This heros does\'nt exist')
Display_menu()

Ty :)
-- 
Brookes Christopher.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] having difficulty installing python

2011-02-25 Thread Dominik Zyla
On Thu, Feb 24, 2011 at 03:56:44PM +, Neven Dragojlovic wrote:
> Please can someone help me? I am trying to install python 2.5.4 on
> MacBookPro running on OS10.6.6, but when I try to set it up on
> Terminal by running "python setup.py install" I get the following:
> IDLE Subprocess: Connection to IDLE GUI failed, exiting.
> Tk_MacOSXSetupTkNotifier: first [load] of TkAqua has to occur in the
> main thread!
> with an extra pop-up saying it can not access port 8833. When I try to
> install that port with "sudo port install `8833'" it again says it can
> not find that port.
> What is going on?
> The trouble started when I installed X11 and fink 0.29.16, with all
> those files coming in and I allowed them. What do I do now?
> 
> Thank you ahead of time,
> Neven

Why don't you try to download `.dmg' image from
http://www.python.org/download/releases/? It can be installed easyly.
Only think you would have to do is to add
`/Library/Frameworks/Python.framework/Versions/$VERSION/bin' at the
begining of your PATH shell variable to use exactly this version, you
would install.

-- 
Dominik Zyla



pgpzCcjCarLww.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Chris Fuller
My "etc" would be the loopback device and an iso image, optionally accompanied 
by wget and cdrecord (or whatever the kids are using these days).

I was also reminded of this story:
http://thedailywtf.com/Articles/ITAPPMONROBOT.aspx

Cheers

On Friday 25 February 2011, Corey Richardson wrote:
> On 02/25/2011 04:49 AM, Steven D'Aprano wrote:
> > Alan Gauld wrote:
> >> Anything you can do locally you can do on the remote
> >> machine with a combination of ssh, rsh, rlogin, telnet etc.
> > 
> > I'd like to remove a CD from the CD drive, and replace it with a
> > different disk.
> > 
> > 
> > Being difficult just for the sake of it-ly y'rs,
> 
> And at that point, the all-encompassing "etc." steps in ;-)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Corey Richardson
On 02/25/2011 04:49 AM, Steven D'Aprano wrote:
> Alan Gauld wrote:
> 
>> Anything you can do locally you can do on the remote
>> machine with a combination of ssh, rsh, rlogin, telnet etc.
> 
> I'd like to remove a CD from the CD drive, and replace it with a 
> different disk.
> 
> 
> Being difficult just for the sake of it-ly y'rs,

And at that point, the all-encompassing "etc." steps in ;-)


-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Steven D'Aprano

Alan Gauld wrote:


Anything you can do locally you can do on the remote
machine with a combination of ssh, rsh, rlogin, telnet etc.


I'd like to remove a CD from the CD drive, and replace it with a 
different disk.



Being difficult just for the sake of it-ly y'rs,


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-25 Thread Alan Gauld


"Bill Allen"  wrote

I have times when it is useful for me to check the environment of a 
user
system on our lan remotely while trouble shooting and issue with 
them.  Now,
this is quite easy to do while I am using a windows system via the 
computer

management console.


I think we are meaning different things by "environment"?
Can you give a specific example?


However, I am trying to do this via a linux workstation
(which is joined to the domain, etc.).   I cannot find a native
facility to duplicate the computer management functions, so I 
thought I

would write a program to fill the need.


Anything you can do locally you can do on the remote
machine with a combination of ssh, rsh, rlogin, telnet etc.
ssh is the safest but requires a bit more admin to set it
up properly for maximum convenience.

Having got remote access its just a case of figuring out
which of the 500 or so Unix commands you need to
use to do the job... :-)

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list of dictionary

2011-02-25 Thread Alan Gauld

"sunil tech"  wrote


i have d=[{'qty':0.0},{'qty':0.0}]

when all the qty is 0.0,
i want to perform some print operation
(only at once, after it checks everything in the list of dictionary 
'd')...


if its not 0.0,
print some message...


Just so I'm clear on the requirement you want something
like:

isZero = True
for each dictionary in d
   if dictionary[qty] is not 0.0
 print some message
 isZero = False
if isZero:
   some print operation

If so that should be easily translated into Python?

HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] comparing strings

2011-02-25 Thread bob gailer

On 2/25/2011 3:23 AM, Corey Richardson wrote:

On 02/25/2011 02:53 AM, Edward Martinez wrote:

  Thanks for the reply. i now understand that python uses either
ASCll or Unicode to compare and to do other things


When comparing string (not unicode) Python uses the underlying hardware 
character representation. This is not always ASCII. On IBM Mainframes it 
is EBCDIC. The ord values are different, and the order is different.


See http://www.dynamoo.com/technical/ascii-ebcdic.htm


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] comparing strings

2011-02-25 Thread Corey Richardson
On 02/25/2011 02:53 AM, Edward Martinez wrote:
>  Thanks for the reply. i now understand that python uses either 
> ASCll or Unicode to compare and to do other things

1. Those are i's, not l's.
2. The first 128 characters of Unicode are the same as the only 128
characters of unicode.

Check out http://qcpages.qc.cuny.edu/~nixon/links/asciiUnicode.html

-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Display all field of a listuples

2011-02-25 Thread Christopher Brookes
It's works. Thank you all.

2011/2/25 bob gailer 

>  On 2/24/2011 4:54 PM, Christopher Brookes wrote:
>
>   Hi i would like to display all the field of my powerAll like this :
>
> Choose a power :
> Froid devorant : Embrase lenemi et le feu bruler
> Flammes infernales : 'Gele lenemi sur place
>
> -
> class Character():
>   def ChoosePouvoirUnique(self):
> print ("Choose a power")
> for Power in powerAll:
> print (Power)
>
> class Power:
> def __init__(self, name, desc):
> self.name = name
> self.desc = desc
>
>
>
>
> powerAll = [
>  Power('Flammes infernales' , 'Embrase lenemi et le feu bruler'),
>  Power('Froid devorant', 'Gele lenemi sur place')]
>
>
> But he won't display it :(
>
> i've try   For PowerName,PowerDesc in powerAll:
> print (PowerName, PowerDesc)
>
> but it doesn't work !
>
>
> When something "does not work" always show us what results you got as well
> as what you wanted.
>
> Also get in the habit of using Capitalized names for classes and
> unCapitalized names for variables and functions.
>
> powerAll is a list of class instaces. You must (in some way) identify the
> attributes of those instances. One way:
>
> for power in powerAll:
>   print (power.name, power.desc)
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
>


-- 
Brookes Christopher.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor