[Tutor] help

2011-02-24 Thread Chris Schiro
Hi,

I am completely new to programming aside from working with basic many years
ago. I purchased a Python book for beginners so I could start from scratch
which has been walking me through just fine until: writing a program to
interact with user for feedback:

 

name=input("What is your name? ")

 

I have found that this line will return an error every time while running
the completed program, unless I enter a number. If I enter a numeric value
the program will continue on as written.

 

I have followed the code exactly per the book. What is the proper coding in
this scenario? 

 

Thank you,

 

Chris

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


Re: [Tutor] Convert string to long

2011-02-24 Thread Alan Gauld


"tee chwee liong"  wrote


is there a way to convert from string to long? for eg: i want to
concatenate all the arrays into data and make it same type (long) as 
data1.


int()

should work ok.
Just remember to supply the base:
eg.

int(s,16) for a hex string

HTH,

Alan G. 



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


Re: [Tutor] help

2011-02-24 Thread Nitin Pawar
instead of input ... use raw_input()

On Thu, Feb 24, 2011 at 9:45 AM, Chris Schiro  wrote:

>  Hi,
>
> I am completely new to programming aside from working with basic many years
> ago. I purchased a Python book for beginners so I could start from scratch
> which has been walking me through just fine until: writing a program to
> interact with user for feedback:
>
>
>
> name=input(“What is your name? “)
>
>
>
> I have found that this line will return an error every time while running
> the completed program, unless I enter a number. If I enter a numeric value
> the program will continue on as written.
>
>
>
> I have followed the code exactly per the book. What is the proper coding in
> this scenario?
>
>
>
> Thank you,
>
>
>
> Chris
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] help

2011-02-24 Thread Noah Hall
> I have found that this line will return an error every time while running
> the completed program, unless I enter a number. If I enter a numeric value
> the program will continue on as written.

When it comes to things like error messages, you need to post enough
code and the _exact_ error message in order for us to easily help you.

> name=input(“What is your name? “)

I imagine it's because you're using Python 2.*, where as the guide is
using the 3.* version.
The function you want in 2.7 is "raw_input", not "input". In 2.7,
"input" takes the string given then runs eval on it.
If you want to know more about this, read
http://docs.python.org/library/functions.html?#input and
http://docs.python.org/library/functions.html?#eval

Otherwise, you can either change your Python installation to Python
3.* to follow your guide, or you can carry on with 2.* and hope for
the best :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2011-02-24 Thread Andre Engels
On Thu, Feb 24, 2011 at 5:15 AM, Chris Schiro  wrote:
> Hi,
>
> I am completely new to programming aside from working with basic many years
> ago. I purchased a Python book for beginners so I could start from scratch
> which has been walking me through just fine until: writing a program to
> interact with user for feedback:
>
>
>
> name=input(“What is your name? “)
>
>
>
> I have found that this line will return an error every time while running
> the completed program, unless I enter a number. If I enter a numeric value
> the program will continue on as written.
>
>
>
> I have followed the code exactly per the book. What is the proper coding in
> this scenario?

What is going on is that you are presumably running some version of
Python 2, whereas the book you are using is intended for Python 3. In
Python 2, to get the same result as input() in Python 3, you have to
use raw_input instead.

name=raw_input(“What is your name? “)

Alternatively, you could of course install Python 3.1 instead of
Python 2.7 (or whatever version you are running).

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2011-02-24 Thread عمـ نوفل ـاد
On 2/24/11, Chris Schiro  wrote:
> Hi,
>
> I am completely new to programming aside from working with basic many years
> ago. I purchased a Python book for beginners so I could start from scratch
> which has been walking me through just fine until: writing a program to
> interact with user for feedback:
>
>
>
> name=input("What is your name? ")
>
>
>
> I have found that this line will return an error every time while running
> the completed program, unless I enter a number. If I enter a numeric value
> the program will continue on as written.
>
>
>
> I have followed the code exactly per the book. What is the proper coding in
> this scenario?
>
>
>
> Thank you,
>
>
>
> Chris
>
>


-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه
كالحقيقة.محمد الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington

___
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-24 Thread Alan Gauld

"Bill Allen"  wrote

I know that I can use the following to get a listing of the 
environment of
my own system.   How can I do similar for another system on my 
network.

This is for administrative purposes.


Environments are user and process specific so you would need to
access the remote machine, access the user account, connect
to the specific process and then run the environment check.

It rarely makes any sense unless its the user themselves
doing the check.

I assume there is a greater requirement at the bavk of this?
What exactly is it you are trying to find out? There may be a better
way.

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] help

2011-02-24 Thread Dipo Elegbede
That line only expects int and say numbers generally.
If you want to print strings, use, raw_input in place of input.
Try that out and then let's have a feedback.
Sent from my BlackBerry wireless device from MTN

On Thu, Feb 24, 2011 at 9:53 AM, Nitin Pawar wrote:

> instead of input ... use raw_input()
>
> On Thu, Feb 24, 2011 at 9:45 AM, Chris Schiro wrote:
>
>>  Hi,
>>
>> I am completely new to programming aside from working with basic many
>> years ago. I purchased a Python book for beginners so I could start from
>> scratch which has been walking me through just fine until: writing a program
>> to interact with user for feedback:
>>
>>
>>
>> name=input(“What is your name? “)
>>
>>
>>
>> I have found that this line will return an error every time while running
>> the completed program, unless I enter a number. If I enter a numeric value
>> the program will continue on as written.
>>
>>
>>
>> I have followed the code exactly per the book. What is the proper coding
>> in this scenario?
>>
>>
>>
>> Thank you,
>>
>>
>>
>> Chris
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Nitin Pawar
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinf
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2011-02-24 Thread Alan Gauld

"Chris Schiro"  wrote

I am completely new to programming aside from working with basic 
many years
ago. I purchased a Python book for beginners so I could start from 
scratch
which has been walking me through just fine until: writing a program 
to

interact with user for feedback:

name=input("What is your name? ")

I have found that this line will return an error every time while 
running

the completed program, unless I enter a number.


It sounds like you are using a Python v3 book but running Python v2.
Python v3 was a major change and not backward compatible with
Python 2.

As a beginner your best bet is probably to upgrade your
copy of Python to v3. The snag with that is that some
3rd party modules are not yet ported to v3, but hopefully,
by the time you need to use them, if ever,  they will be!

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] help

2011-02-24 Thread Dipo Elegbede
i can mail free books on python 2. if you want.
starting out with python 3.XXX restricts the amount of help you can get and
also free resources.
most resources i have come across are python 2.XXX.
cheers.

On Thu, Feb 24, 2011 at 9:58 AM, Andre Engels  wrote:

> On Thu, Feb 24, 2011 at 5:15 AM, Chris Schiro 
> wrote:
> > Hi,
> >
> > I am completely new to programming aside from working with basic many
> years
> > ago. I purchased a Python book for beginners so I could start from
> scratch
> > which has been walking me through just fine until: writing a program to
> > interact with user for feedback:
> >
> >
> >
> > name=input(“What is your name? “)
> >
> >
> >
> > I have found that this line will return an error every time while running
> > the completed program, unless I enter a number. If I enter a numeric
> value
> > the program will continue on as written.
> >
> >
> >
> > I have followed the code exactly per the book. What is the proper coding
> in
> > this scenario?
>
> What is going on is that you are presumably running some version of
> Python 2, whereas the book you are using is intended for Python 3. In
> Python 2, to get the same result as input() in Python 3, you have to
> use raw_input instead.
>
> name=raw_input(“What is your name? “)
>
> Alternatively, you could of course install Python 3.1 instead of
> Python 2.7 (or whatever version you are running).
>
> --
> André Engels, andreeng...@gmail.com
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com
Mobile Banking Solutions | Transaction Processing | Enterprise Application
Development
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] merging 2 files.

2011-02-24 Thread nitin chandra
Hello Every One,

I have A problem :)

I have a file with data collected in with 5 colums in a CSV format.
eg. test.csv (below) format
---
26290,75.318669993,28.390548328,"WELL 3","WELL 3 MENCHOKE FUNCTIOANL"
26290,75.316180604,28.397089997,"WT 1","WT 1 BHIEND SCHOOL FUNCTIONAL"
26290,75.316270357,28.397127539,"HP1","HP1 PRIMERY SCHOOL
SHYOPURA NOFUNCTIONAL"
26290,75.318428057,28.390289283,"GLR 1","GLR1 MENCHOKE FUNCTIONAL"
26290,75.319708803,28.389555882,"WELL 1","WELL1 BUS STAND NONFUNCTIONAL"
26290,75.316967421,28.395669652,"TW 1","WELL 2 FRONT OF SCHOOL
NONFUNCTIONAL"
40988,75.269703,28.369377,"HPG1","HPG1 WARD NO. 7"
40988,75.270543,28.368524,"GLR1","GLR1 IN SCHOOL"
40988,75.270429,28.368761,"WT1","WT1 IN SCHOOL"
40988,75.2711484196972,28.3689626934834,"OW1+TW1","OW1+TW1 W. N. 7"
40988,75.271347,28.369323,"GLR1","GLR1 WARD NO. 7"
41458,75.282509856,28.407150085,"GLR1","GLR1 PO KE PASS"
41458,75.2824,28.40718,"GLR2","GLR2 P.O. KE PASS"
--

The other file is Jhun.csv


id,loc_id,habitation_name,source_type,type_habit,location,longitude,latitude,functional_status,operational_status,quality_status,village_quality_status,yield,seasonal_fluctuation,water_fluctuation_min,water_fluctuation_max,avg_depth,para_ph,para_tds,para_cl,para_f,para_no3,bact,rep_status,remark

88075,60942,Raghunathpura,TW3,MH,Madhaya
Mein,,,F,In-Use,Potable,Good,Good,No-Change,0,0,140,8,680,300,1,100,,,remarks4

88074,60942,Raghunathpura,TW2,MH,School Ke
pas,,,F,In-Use,Potable,Good,Good,No-Change,0,0,150,8,620,320,0.5,45,,,remarks3

88073,60942,Raghunathpura,TW1,MH,Harizen basti
,,,F,In-Use,Potable,Good,Good,No-Change,0,0,120,8,810,380,1,45,,,remarks2

88072,60942,Raghunathpura,HpGovt1,MH,Raste Per,,,NF,,,Rep,remarks1

83613,59500,Dhani Hukma,TW3,MH,rasta per,,,NF,,,Non Rep,remarks8

83612,59500,Dhani Hukma,TW2,MH,rasta
per,,,F,In-Use,Potable,Good,Good,No-Change,0,0,140,7.5,660,220,0.5,45,,,remarks7

83611,59500,Dhani Hukma,TW1,MH,rasta
per,,,F,In-Use,Potable,Good,Good,No-Change,0,0,135,7.5,740,180,1,45,,,remarks6

83610,59500,Dhani Hukma,HpGovt5,MH,chowk mai,,,NF,,,Non Rep,remarks5

83609,59500,Dhani Hukma,HpGovt4,MH,chowk mai,,,NF,,,Non Rep,remarks4

83608,59500,Dhani Hukma,HpGovt3,MH,rasta per,,,NF,,,Non Rep,remarks3

83607,59500,Dhani Hukma,HpGovt2,MH,rasta
per,,,F,In-Use,Potable,Good,Good,No-Change,0,0,80,7.5,690,200,0.5,45,,,remarks2

83606,59500,Dhani Hukma,HpGovt1,MH,near ragu
home,,,NF,,,Non Rep,remarks1

1085,11284,Ashok Nagar,HpGovt1,MH,IN SCHOOL,,,NF,,,Rep,

**
PROBLEM : I need to pick the "first coloum" from test.csv AND SEARCH
in jhun.csv "second coloum" , IF matches read that row from jhun.csv,
break it into individual values , concat with the first file,
test.csv, individual values and write to a third file, eg. merged2.csv

currently the data in both the file is 6 - 10,000 rows max.

I am in need of the solution as client breathing down my neck.

this is my 5th attempt.

Thank you VERY much

Nitin

/
import os, sys, re

f = open ('Jhun_Water_source_details_hab.csv', 'r')
f2 = open ('test.csv', 'r')
fw = f.readline()

# read from Jhun Water csv file
f11 = f.read()
print "This is from Jhun_Water_source_details_hab.csv file"
#print col11 + col12 + col13 + col14
print f11

# read from test csv file
f21 = f2.readline()
ln3 = f21.rstrip('\r\n')
ln4 = ln3.strip('""')
row2 = ln4.split(',')
#print row2
col21 = row2[:1]
col22 = row2[1:2]
col23 = row2[2:3]
print "This is from test.csv file"
#print col21 + col22 + col23
print f21

for line in f11:
match = None
if line.find(col21) == 0:
pass
if line.find(col21) == f11:
print line1
break


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


Re: [Tutor] licensing python work?

2011-02-24 Thread Steven D'Aprano

Wayne Werner wrote:

If you don't care how people use it at all, just release your code into the
public domain, then it doesn't matter how they use it.


That's actually not as easy as it sounds. It depends where you are. In 
some jurisdictions, such as the USA, it's hard to put work into the 
public domain in such a way as it sticks. Just look at the effort the 
Creative Commons people going to in order to make their "public domain" 
licence bulletproof.


http://creativecommons.org/choose/zero/

You might say, "What difference does it make, I'm not going to sue you". 
Sure, but what if you get hit by a bus, and your heirs come after me 
with a fully-loaded lawyer for "stealing" your valuable intellectual 
"property"?


If your release isn't bulletproof, I'm not going to touch it.


Personally I recommend two free/open source licences: the MIT licence 
and the GPL.


If you want people to use your work, and you don't care how, use the MIT 
licence:


http://www.opensource.org/licenses/mit-license.php

The only restriction is that if they re-distribute your software, they 
have to include the copyright notice.



If you want your uses to "share and share alike", use the GPL:

http://www.opensource.org/licenses/gpl-license

But if you're serious about having others use your software, you *must* 
be GPL-compatible:


http://www.dwheeler.com/essays/gpl-compatible.html

Whatever you do, don't make up your own licence unless you are a lawyer 
specializing in *international* copyright law and software licences! 
Every time an amateur makes up a new open source licence, God buys a 
retail version of Windows.




--
Steven

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


Re: [Tutor] merging 2 files.

2011-02-24 Thread Martin A. Brown

Hi Nitin,

 : currently the data in both the file is 6 - 10,000 rows max.

Many ways to skin this cat.  You say that the files are 6-10,000 
lines.  These are small files.  Load them into memory.  Learn how to 
use csv.reader.

 : PROBLEM : I need to pick the "first coloum" from test.csv AND 
 : SEARCH in jhun.csv "second coloum" , IF matches read that row 
 : from jhun.csv, break it into individual values , concat with the 
 : first file, test.csv, individual values and write to a third 
 : file, eg. merged2.csv

Always break your problem into its parts and examine your data.  
There's probably a data structure that suits your needs.  You have a 
lookup table, 'jhun.csv' (your second file).  Given your problem 
description, it seems like the first column in 'jhun.csv' has your 
unique identifiers.  

If that's accurate, then read that second file into some sort of 
in-memory lookup table.  A key, perhaps in a dictionary, would you 
say?

Then, you can simply read your other file (test.csv) and print to 
output.  This is one quick and dirty solution:

  import csv

  # -- build the lookup table
  #
  lookup = dict()
  file0 = csv.reader(open('jhun.csv','r'))
  for row in file0:
  lookup[ row[0] ] = row

  # -- now, read through the 
  #  
  file1 = csv.reader(open('test.csv','r'))
  for row in file1:
  exists = lookup.get( row[0], None )
  if exists:
  print row, exists  # -- print out only what you want
  else:
  pass  # -- do you need to do something if no lookup entry?

At 10^4 lines in the lookup file, you could easily do this in 
memory.

There are many tools for dealing with structured data, even loosely 
structured data such as csv.  When faced with a problem like this in 
the future, ask yourself not only about what tools like csv.reader 
you may have at your disposal, but also what data structures are 
suited to your questions of your data.

 : I am in need of the solution as client breathing down my neck.

They always do.  Wear a scarf.

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] comparing strings

2011-02-24 Thread Dave Angel

On 01/-10/-28163 02:59 PM, Edward Martinez wrote:

On 02/23/11 19:29, Corey Richardson wrote:

On 02/23/2011 10:22 PM, Edward Martinez wrote:

Hi,

I'm new to the list and programming.
i have a question, why when i evaluate strings ie 'a'> '3' it reports
true, how does python come up with that?

Welcome! As far as I know, it compares the value of the ord()'s.


ord('a')

97

ord('3')

51

This is their number in the ASCII system. You can also do this:


chr(97)

'a'

chr(51)

'3'



A string is effectively an array of characters.  Each one may be ASCII 
or Unicode or other, depending partly on your Python version.


Each character has an ord() between 0 and 255, or between 0 and 65535. 
Except for some values below 0x20  (eg. tab, newline), these are 
printable.  So you can make a chart for your own system with a fairly 
simple loop.


Comparison is done left to right on the two strings, comparing one 
character at a time.  If there are no control characters, this 
approximates what a dictionary order would do.  But notice that all the 
capital letters appear before any of the lowercase characters. And that 
if you have accented characters, they're generally nowhere near the 
unaccented versions.


One other point:  if one string begins with all the characters in the 
other (eg. 'cat' and 'catatonic'), the longer string is then considered 
"greater".


DaveA


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


Re: [Tutor] Convert string to long

2011-02-24 Thread Steven D'Aprano

tee chwee liong wrote:
hi, 
 
is there a way to convert from string to long? 


my_string = "1234"
my_long = long(my_string)

We're happy to help you, but you should make some effort to help 
yourself. Have you worked through the Python tutorial? Don't just *read* 
it, actually follow the instructions and *do* it.


From Python 2.5 on, the function int() will do the same thing and 
there's never any reason to use long(). From Python 3, long() is removed.


int() (and long) also take an optional second argument, the base to use:

>>> int("11")  # decimal by default
11
>>> int("11", 2)  # binary
3


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


[Tutor] Clubbing simillar elements together in a list with repeating elements

2011-02-24 Thread ranjan das
I have a list

a=[1,2,3,4,2,5,5,4,6,7,8]

I want to club the repeating elements together and my output should be
something like

a_new=[ [1], [2,2], [3], [4,4] , [5,5,5],[6], [7], [8]]

How do I do this?

I tried the following but it is not giving me the desired result


a=[1,2,3,2,3,4,5,4,5,5,6]

Output=[]
Unique=[]
Duplicate=[]

FinList=[]


for element in a:
if element not in Unique:
Unique.append(element)
else:
Duplicate.append(element)



for element in Unique:

if element in Duplicate:

count=0

for i in Duplicate:
if i==element:
count=count+1


for j in range(count+1):
FinList.append(element)

else:

FinList.append([element])



print Unique

print Duplicate

print FinList

*result:*

Unique=[1, 2, 3, 4, 5, 6]
Duplicate=[2, 3, 4, 5, 5]

FinList=[[1], 2, 2, 3, 3, 4, 4, 5, 5, 5, [6]]

I want the FinList as [ [1], [2,2], [3,3], [4,4] , [5,5,5],[6]]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert string to long

2011-02-24 Thread tee chwee liong

> int(s,16) for a hex string
> 

great but the leading zeroes are being truncated. 
i want it to be: 
0x00180400L

>>> array0='00180400'
>>> array1=''
>>> array=array0+array1
>>> a=int(array,16)
>>> print a
647038726439367532107969464256319505531941876229785714677657987186688
>>> print hex(a)
0x180400L
>>> 
 
pls advise.   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Clubbing simillar elements together in a list with repeating elements

2011-02-24 Thread Hugo Arts
Won't give you all the ansers, but here's a few tips.

On Thu, Feb 24, 2011 at 12:29 PM, ranjan das  wrote:
>
> I have a list
>
> a=[1,2,3,4,2,5,5,4,6,7,8]
>
> I want to club the repeating elements together and my output should be
> something like
>
> a_new=[ [1], [2,2], [3], [4,4] , [5,5,5],[6], [7], [8]]
>

In you original list a, there's only 2 fives. Please make sure that
you type everything in accurately, and use the same example
throughout, or we get confused far more easily.

> How do I do this?
>
> I tried the following but it is not giving me the desired result
>
>
> for element in Unique:
>     if element in Duplicate:
>     count=0
>     for i in Duplicate:
>     if i==element:
>     count=count+1
>
>     for j in range(count+1):
>     FinList.append(element)
>     else:
>     FinList.append([element])
>

The mistake is in that piece. Note that if the element is not in
duplicate, you append it *inside* a separate list. But if it *is* in
duplicate, you append all the elements to FinList directly, *without*
creating a separate list for them. Note that you don't have to use the
range() function. Try this in the interpreter:

>>> [5] * 3
[5, 5, 5]

Can you use that neat little multiply trick to avoid having to loop
over a range?

This problem has come up before, and you can do it much, much quicker.
You can create the Unique list much easier by simply using the set()
function. Then, the count() method counts how often an item appears in
a list.

Finally, we can make it even shorter with the groupby function from
the itertools package, which was pretty much made for this:

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


Re: [Tutor] Convert string to long

2011-02-24 Thread Walter Prins
On 24 February 2011 11:50, tee chwee liong  wrote:

>  > int(s,16) for a hex string
> >
>
> great but the leading zeroes are being truncated.
>

You need to seperate the concept of display/formatting of some thing from
the actual thing/value being displayed.

Normally when we humans communicate numbers and or work with them, leaading
zero's are not used, so normally most computer systems and languages will
not display numbers with leading zeros by default.  It is therefore up to
you to *tell* the computer you want leading zeros in order for it to produce
them from the actual value being represented.

Furthermore you need to distinguish (as does the computer) between different
object types (namely strings and numbers) as they are different animals
which are handled differently by the computer.

A number, as already mentioned, will be by default not displayed with
leading zeros as that's normally how humans are used to seeing numbers.

A string however is a data structure that can contain arbitrary characters.
The computer therefore will generally just display a string with whatever is
in it (some exceptions apply for escape characters etc depending on context
etc. but ignore that for the moment.)

Now, a string may contain characters that happens to be the character
representation of number (with or without leading zeros) but yet to the
computer this remains a string and only a string, until you *explicitly*
tell it otherwise and explicitly convert it into an actual number object.
After you've done this of course, the computer will know that the thing now
being dealt with is in fact a number, and will therefore display/format the
number as it usually does (e.g. without leading zeros), again, unless you
tell it to display/format it otherwise.

So at the risk of belaboring the points: 1) Get a handle on the fact that
numbers and strings are different things, and that on the one hand you're
converting between them.  2) Get a handle on the fact that different things
can furthermore be displayed/formatted in a variety of different ways, and
there may be many ways to display or represent a given thing, which again is
up to *you* to control/specify.

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


Re: [Tutor] help

2011-02-24 Thread bob gailer

Request:

When posting a question use a meaningful subject line, as some of us 
track email by subject.


--
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] Convert string to long

2011-02-24 Thread Joel Goldstick
On Thu, Feb 24, 2011 at 8:08 AM, Walter Prins  wrote:

>
>
> On 24 February 2011 11:50, tee chwee liong  wrote:
>
>>  > int(s,16) for a hex string
>> >
>>
>> great but the leading zeroes are being truncated.
>>
>
> You need to seperate the concept of display/formatting of some thing from
> the actual thing/value being displayed.
>
> Normally when we humans communicate numbers and or work with them, leaading
> zero's are not used, so normally most computer systems and languages will
> not display numbers with leading zeros by default.  It is therefore up to
> you to *tell* the computer you want leading zeros in order for it to produce
> them from the actual value being represented.
>
> Furthermore you need to distinguish (as does the computer) between
> different object types (namely strings and numbers) as they are different
> animals which are handled differently by the computer.
>
> A number, as already mentioned, will be by default not displayed with
> leading zeros as that's normally how humans are used to seeing numbers.
>
> A string however is a data structure that can contain arbitrary
> characters.  The computer therefore will generally just display a string
> with whatever is in it (some exceptions apply for escape characters etc
> depending on context etc. but ignore that for the moment.)
>
> Now, a string may contain characters that happens to be the character
> representation of number (with or without leading zeros) but yet to the
> computer this remains a string and only a string, until you *explicitly*
> tell it otherwise and explicitly convert it into an actual number object.
> After you've done this of course, the computer will know that the thing now
> being dealt with is in fact a number, and will therefore display/format the
> number as it usually does (e.g. without leading zeros), again, unless you
> tell it to display/format it otherwise.
>
> So at the risk of belaboring the points: 1) Get a handle on the fact that
> numbers and strings are different things, and that on the one hand you're
> converting between them.  2) Get a handle on the fact that different things
> can furthermore be displayed/formatted in a variety of different ways, and
> there may be many ways to display or represent a given thing, which again is
> up to *you* to control/specify.
>
> Walter
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
Take a look at this code.  You get your hex number as a string.

It has 0x on the left which shows its hexidecimal.  Get rid of it with the
slice (h[2:] in my example)
Now, use the zfill method on the string to pad the result to 5 characters.
You can pad to any size you want.
Then add back the 0x prefix

q.e.d.

>>> h = hex(546)
>>> h
'0x222'
>>> n = h[2:]
>>> n
'222'
>>> n.zfill(5)
'00222'
>>> '0x' + n.zfill(5)
'0x00222'
>>>


This can all be simplified (well .. shortened!) to

>>> '0x' + hex(543)[2:].zfill(5)
'0x0021f'


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


Re: [Tutor] Convert string to long

2011-02-24 Thread tee chwee liong

>>> '0x' + hex(543)[2:].zfill(5)
'0x0021f'

this is a good way but it's still in string format. but if i convert it to 
long, then the leading 0s will be truncated. i guess can't have it both way. 
 
 
 

 
 

___ 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] Convert string to long

2011-02-24 Thread Andre Engels
On Thu, Feb 24, 2011 at 3:03 PM, tee chwee liong  wrote:
 '0x' + hex(543)[2:].zfill(5)
> '0x0021f'
>
> this is a good way but it's still in string format. but if i convert it to
> long, then the leading 0s will be truncated. i guess can't have it both way.

A long is just a number. You cannot say that a number has or does not
have leading zeroes. Only _a representation of_ that number has. The
numbers 3, 1+2 and 3 are all the same number, so you
cannot say that the first does not have leading zeroes whereas the
last one has. To make the concept of 'leading zeroes' a meaningful
one, you _first_  have to re-convert the number to a string. Whether
or not there are leading zeroes depends on how that conversion is
done. If you use Python's standard conversion method, the result will
be a string representation without leading zeroes, but there are other
conversion methods that do give leading zeroes.

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert string to long

2011-02-24 Thread Joel Goldstick
On Thu, Feb 24, 2011 at 9:03 AM, tee chwee liong  wrote:

>  >>> '0x' + hex(543)[2:].zfill(5)
> '0x0021f'
>
> this is a good way but it's still in string format. but if i convert it to
> long, then the leading 0s will be truncated. i guess can't have it both way.
>
>
>
>
>
>
>
>
>
> ___ Tutor maillist -
> Tutor@python.org To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

As was explained by another poster earlier, the idea of leading zeros in the
internal representation of a number is meaningless.  If I have 05 of
something, or I have 5 of something  I have the same number of things.  So,
when the python shell prints out a number, it has no reason to print leading
zeros.  How would it know you want them?  If you do want leading zeros
because it makes your display look more proper, then you do the string
formatting to get what you need.

Go back and read some tutorials or the python manual to understand data
types.

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


[Tutor] Help on Python Looping Please

2011-02-24 Thread pyhx0r
Dear All,


I’m new in programming and I’m studying Python now. I use Python 3.1.2 and
learn from Dive Into Python 3 book (Mark Pilgrim, Thank you very much for
him). I’ve learned list, tuple, set, dictionary and little bit about
looping. I’m so confused about looping in first Python Program in that book
(humanize.py), it’s the code:


SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],

1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}



def approximate_size(size, a_kilobyte_is_1024_bytes=True):

'''Convert a file size to human-readable form.

   Keyword arguments:

   size -- file size in bytes

   a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024

   if False, use multiples of 1000

   Returns: string

'''

if size < 0:

raise ValueError('number must be non-negative')



multiple = 1024 if a_kilobyte_is_1024_bytes else 1000

for suffix in SUFFIXES[multiple]:

size /= multiple

if size < multiple:

return '{0:.1f} {1}'.format(size, suffix)



raise ValueError('number too large')



if __name__ == '__main__':

print(approximate_size(1, False))

print(approximate_size(1))


 Result:

1.0 TB

931.3 GiB


I’ve shorted the code be:


>>> SUFFIXES = {1000: ['KB','MB','GB'],

1024: ['KiB','MiB','GiB']}

>>> multiple = 1000

>>> size = 2300

>>> for suffix in SUFFIXES[multiple]:

size /= multiple

if size < multiple:

'{0:.1f} {1}'.format(size, suffix)





'2.3 KB'

'0.0 MB'

'0.0 GB'

>>>


*Why do in my code, it loops to all values and not in Mark Pilgrim’s code?*



Best Regards,
[ pyhx0r - hx0r-labs.org ]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help on Python Looping Please

2011-02-24 Thread Walter Prins
On 24 February 2011 14:52, pyhx0r  wrote:

> *Why do in my code, it loops to all values and not in Mark Pilgrim’s code?
> *
>
>
Because in Mark's code the loop is terminated by the return statement
(contained in the utility function approximate_size().)  In your code you've
removed the entire function including the return statement, consequently the
loop runs to completion.

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


[Tutor] Python object

2011-02-24 Thread Christopher Brookes
Hi, i'm new in python.
I'm trying to create a small fight program in object.

I've created __init__ (its works) but when i'm trying to display init param
i'm getting param and "None" every time. Why ?

def GetAllAtrib(self):
print '---'
print self.name
print self.description
print self.type
print '---'

give ->>

---
Klaitos
Soldier very strong
Soldier
---
*None   *-- WHY ARE U HERE
??

Yours,



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


Re: [Tutor] Python object

2011-02-24 Thread James Reynolds
I don't understand what you are trying to do?

I'm assuming def GetAllAtrib is a method within a class; perhaps you could
copy more the code base?

It seems to be locating the three elements you have in that method just
fine, but I'm guessing you have another print statement somewhere that is
causing it to print None.


On Thu, Feb 24, 2011 at 10:48 AM, Christopher Brookes <
chris.klai...@gmail.com> wrote:

> Hi, i'm new in python.
> I'm trying to create a small fight program in object.
>
> I've created __init__ (its works) but when i'm trying to display init param
> i'm getting param and "None" every time. Why ?
>
> def GetAllAtrib(self):
> print '---'
> print self.name
> print self.description
> print self.type
> print '---'
>
> give ->>
>
> ---
> Klaitos
> Soldier very strong
> Soldier
> ---
> *None   *-- WHY ARE U HERE
> ??
>
> Yours,
>
>
>
> --
> Brookes Christopher.
>
> ___
> 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] Help on Python Looping Please

2011-02-24 Thread Dave Angel

On 01/-10/-28163 02:59 PM, pyhx0r wrote:

Dear All,



 multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
 for suffix in SUFFIXES[multiple]:
 size /= multiple
 if size<  multiple:
 return '{0:.1f} {1}'.format(size, suffix)



 

I’ve shorted the code be:



SUFFIXES = {1000: ['KB','MB','GB'],


 1024: ['KiB','MiB','GiB']}



multiple = 1000



size = 2300
for suffix in SUFFIXES[multiple]:

 size /= multiple
 if size<  multiple:
 '{0:.1f} {1}'.format(size, suffix)




*Why do in my code, it loops to all values and not in Mark Pilgrim’s code?*



(Is there a reason you double-spaced all that code?  It makes it very 
hard to read, and quite difficult to quote, since I had to delete every 
other line.)


You wrote your code inline, and not as a function.  And you omitted the 
return statement.  So the loop won't return, it'll run to completion.


Another way to exit a loop early is to use the break statement.


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


Re: [Tutor] Python object

2011-02-24 Thread Peter Otten
Christopher Brookes wrote:

> Hi, i'm new in python.
> I'm trying to create a small fight program in object.
> 
> I've created __init__ (its works) but when i'm trying to display init
> param i'm getting param and "None" every time. Why ?
> 
> def GetAllAtrib(self):
> print '---'
> print self.name
> print self.description
> print self.type
> print '---'
> 
> give ->>
> 
> ---
> Klaitos
> Soldier very strong
> Soldier
> ---
> *None   *-- WHY ARE U HERE

My crystall ball says: because you invoke the above method with something 
like

print soldier.GetAllAttrib()

instead of just

soldier.GetAllAttrib()

If I'm guessing wrong please provide the relevant source code.
By the way, show_all_attributes() would be a better name for your method as 
it would make the problem in your code obvious.


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


Re: [Tutor] Help on Python Looping Please

2011-02-24 Thread pyhx0r
Dear All,

Thank you for your advise, it's helpful for me.

NB: To DaveA, It was copy-paste from my notepad so the indentation went
wrong :(


+---+--+---+
| py | h | x0r |
+---+--+---+
■ 1 3 0 E2 C 9 ■
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] having difficulty installing python

2011-02-24 Thread Neven Dragojlovic
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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] merging 2 files.

2011-02-24 Thread nitin chandra
On Thu, Feb 24, 2011 at 9:18 PM, nitin chandra  wrote:
> Hi Martin,
>
> Thanks a lot. It did work, but I am trying to break it down and  understand
>
>>  import csv
>>
>>  # -- build the lookup table
>>  #
>>  lookup = dict()
>>  file0 = csv.reader(open('jhun.csv','r'))
>>  for row in file0:
>>      lookup[ row[0] ] = row
>>
>>  # -- now, read through the
>>  #
>>  file1 = csv.reader(open('test.csv','r'))
>>  for row in file1:
>
> modified it to
>
> for row1 in file1:
>
>>      exists = lookup.get( row[0], None )
>
>     exists = lookup.get(row1[0], None)
>
>>      if exists:
>>          print row, exists  # -- print out only what you want
>>      else:
>>          pass  # -- do you need to do something if no lookup entry?
>>
>
> but some how It is reading "test.csv" from row 8000+ onwards not from
> 1st row. Dunno if it doing the same thing with jhun.csv. screen
> scrolls by.
>
>>
>>  : I am in need of the solution as client breathing down my neck.
>>
>> They always do.  Wear a scarf.
>>
>> -Martin
>>
> I shall try a fire proof scarf ... thanks :)
>
> Nitin
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python object

2011-02-24 Thread Steve Willoughby

On 24-Feb-11 08:13, James Reynolds wrote:

I don't understand what you are trying to do?

I'm assuming def GetAllAtrib is a method within a class; perhaps you
could copy more the code base?

It seems to be locating the three elements you have in that method just
fine, but I'm guessing you have another print statement somewhere that
is causing it to print None.


Or perhaps calling the method from an IDE or interactive prompt, where 
the print statements in the method are printing as intended, but the 
interactive environment itself is printing the return value from the 
method?  This could happen if you did this at the prompt:


>>> print object.GetAllAtrib()

This is a case where giving us more information about what you're doing 
helps us answer your question better.



--steve




On Thu, Feb 24, 2011 at 10:48 AM, Christopher Brookes
mailto:chris.klai...@gmail.com>> wrote:

Hi, i'm new in python.
I'm trying to create a small fight program in object.

I've created __init__ (its works) but when i'm trying to display
init param i'm getting param and "None" every time. Why ?

def GetAllAtrib(self):
 print '---'
 print self.name 
 print self.description
 print self.type
 print '---'

give ->>

---
Klaitos
Soldier very strong
Soldier
---
*None *-- WHY ARE U HERE ??

Yours,



--
Brookes Christopher.

___
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] relative imports

2011-02-24 Thread Alex Hall
Sorry, I forgot to say that the error is:
ValueError: attempted relative import in non-package.

On 2/24/11, Alex Hall  wrote:
> Hi all,
> I am trying to place some common files into a folder so that all files
> in other folders can access the common files. That is, the file for a
> card class, a deck class, and so on are all in a "common" folder. At
> this folder's level are also all folders for games so that all games'
> files can simply say
> from .common import cards
> However, it is not working out that way. Attached is a simple example.
> Try running a\common\vars.py and you will get an error, even though
> the "a" folder has a __init__.py file in it.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
>


-- 
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


Re: [Tutor] Help on Python Looping Please

2011-02-24 Thread Walter Prins
On 24 February 2011 16:22, Dave Angel  wrote:

>
> (Is there a reason you double-spaced all that code?  It makes it very hard
> to read, and quite difficult to quote, since I had to delete every other
> line.)
>

For what it's worth the code came out perfectly fine on my email reader
(GMail). (No double spacing, courier formatted, all in all pretty easy to
read. What email client are you using?)

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


[Tutor] Dictionnaries in object

2011-02-24 Thread Christopher Brookes
Hi,

I want to create some powers in my fight program.
I want to know if dictionnaries is the best solution to do it.

For now its look like this :


//French name and description, don't care about it ;)

power1= {}
power1['Name'] = 'Flammes infernales'
power1['Description'] = 'Embrase lenemi et le feu bruler'

power2= {}
power2['Name'] = 'Froid devorant'
power2['Description'] = 'Gele lenemi sur place'

powerAll= [power1,power2]

but if i want to create like 20 powers, it will be long no ? is there any
solution shorter (and better ?)

Thank you for reading,

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


Re: [Tutor] Dictionnaries in object

2011-02-24 Thread Corey Richardson
On 02/24/2011 01:58 PM, Christopher Brookes wrote:
> Hi,
> 
> I want to create some powers in my fight program.
> I want to know if dictionnaries is the best solution to do it.
> 
> For now its look like this :
> 
> 
> //French name and description, don't care about it ;)
> 
> power1= {}
> power1['Name'] = 'Flammes infernales'
> power1['Description'] = 'Embrase lenemi et le feu bruler'
> 
> power2= {}
> power2['Name'] = 'Froid devorant'
> power2['Description'] = 'Gele lenemi sur place'
> 
> powerAll= [power1,power2]
> 
> but if i want to create like 20 powers, it will be long no ? is there any
> solution shorter (and better ?)
> 
> Thank you for reading,

powerAll = {"Flammes infernales": "Embrase lenemi et le feu bruler",
"Froid devorant": "Gele lenemi sur place"}

Have it implicit that the key is the name and the value is the
description. That's how I would do it, at least.

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


Re: [Tutor] Dictionnaries in object

2011-02-24 Thread bob gailer

On 2/24/2011 1:58 PM, Christopher Brookes wrote:

Hi,

I want to create some powers in my fight program.
I want to know if dictionnaries is the best solution to do it.

For now its look like this :


//French name and description, don't care about it ;)

power1= {}
power1['Name'] = 'Flammes infernales'
power1['Description'] = 'Embrase lenemi et le feu bruler'

power2= {}
power2['Name'] = 'Froid devorant'
power2['Description'] = 'Gele lenemi sur place'

powerAll= [power1,power2]

but if i want to create like 20 powers, it will be long no ? is there 
any solution shorter (and better ?)



1 - define a Power class and create instances

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')]

--
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


[Tutor] Display all field of a listuples

2011-02-24 Thread Christopher Brookes
  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 !

Thank you again..

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


Re: [Tutor] Dictionnaries in object

2011-02-24 Thread bob gailer

Always reply-all so a copy goes to the list.

On 2/24/2011 2:20 PM, Christopher Brookes wrote:

Oh yes, did'nt think about it. I love this solution Ty :) !

BTW i add Character class, how can i add to it ONE power ?


Sorry I don't understand.


class Character():
""" Classe du personnage, ses movements, attaques, geston de 
l'expérience et du niveau"""
def 
__init__(self,name,description,type,strenght,intelligence,agility,health,level):

self.name  = name
self.description = description
self.type = type
self.strenght = strenght
self.intelligence = intelligence
self.agility = agility
self.health = health
self.level = level

def hit(self,target):
""" Calcule la puissance du coup et réduit la vie de la cible"""
target.health -=self.strenght  // care about it is  - =
print (self.name , "hit",target.name 
, "for", self.strenght, "damage")





Sorry, object is very new for me...


2011/2/24 bob gailer mailto:bgai...@gmail.com>>

On 2/24/2011 1:58 PM, Christopher Brookes wrote:

Hi,

I want to create some powers in my fight program.
I want to know if dictionnaries is the best solution to do it.

For now its look like this :


//French name and description, don't care about it ;)

power1= {}
power1['Name'] = 'Flammes infernales'
power1['Description'] = 'Embrase lenemi et le feu bruler'

power2= {}
power2['Name'] = 'Froid devorant'
power2['Description'] = 'Gele lenemi sur place'

powerAll= [power1,power2]

but if i want to create like 20 powers, it will be long no ?
is there any solution shorter (and better ?)

1 - define a Power class and create instances

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')]

-- 
Bob Gailer

919-636-4239
Chapel Hill NC




--
Brookes Christopher.



--
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] Display all field of a listuples

2011-02-24 Thread Alex Hall
On 2/24/11, 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)
You need a __init__() function in this class, as with any class.
>
> 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 :(
How are you calling it? That is, what code are you using to try to
display the contents of the list? Is powerAll supposed to be a
variable in a class? If so, it should be self.powerAll.
>
> i've try   For PowerName,PowerDesc in powerAll:
> print (PowerName, PowerDesc)
>
> but it doesn't work !
What does that mean? It prints something strange, or you get an error?
What error is it? Also, "for" should be lowercase, though I am
honestly not sure that this is a requirement(though I believe it is).
>
> Thank you again..
>
> --
> Brookes Christopher.
>


-- 
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


Re: [Tutor] having difficulty installing python

2011-02-24 Thread Steven D'Aprano

Neven Dragojlovic wrote:

Please can someone help me? I am trying to install python 2.5.4 on
MacBookPro running on OS10.6.6, 



This is a mailing list for beginners to programming Python, not a 
general Python mailing list. It's quite likely that nobody here knows 
enough about installing software on OS X to help you.


I suggest you take this question to either a dedicated Mac forum, or to 
the main Python help list python-l...@python.org, which is also 
available as a newsgroup comp.lang.python.



A couple of further comments:

Unless you really have need for Python 2.5, I don't think it's worth 
wasting your time on such an old version. The current versions of Python 
are 2.7 and 3.2, so you are missing out on probably 3-5 years of bug 
fixes and new features. I recommend you go straight to 2.7 and 3.2. If 
you only want to install one version, just use 2.7.


If 2.7 and 3.2 aren't yet available for Mac, go for 2.6 and 3.1. Don't 
under any circumstances use 3.0, it was rubbish :)




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.


I don't know what the "port" command might do on OS X (possibly it means 
MacPorts, see below), but I think you are misunderstanding the error 
message. Normally port refers to a networking port, and if IDLE is 
complaining about not accessing port 8833, that means your firewall is 
blocking access to it. You don't install port 8833, because it is 
automatically there, but you need to tell your firewall to trust 
connections to it from localhost.


You might also like to use the MacPorts program for managing Unix 
software on your Mac. I haven't used it myself, I don't have a Mac, but 
I have heard good things about it.




--
Steven

___
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-24 Thread Steven D'Aprano

Alex Hall wrote:

On 2/24/11, 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)



You need a __init__() function in this class, as with any class.


That's not strictly correct. You don't *need* an __init__ method, unless 
your class needs to be initialised. Most classes will, but some do not.



[...]

Also, "for" should be lowercase, though I am
honestly not sure that this is a requirement(though I believe it is).


It certainly is. Python is case sensitive, so "for" and "FOR" and "For" 
are different. "for" is a Python keyword with special meaning. The 
others are just words with no special meaning.





--
Steven

___
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-24 Thread Christopher Brookes
class Character:
   def __init__(self, name):
self.name = name

def ChoosePouvoirUnique(self):
""" Permet de choisir le pouvoir unique du personnage """
print ("Veuillez choisir votre pouvoir unique dans la liste")


for PowerNom,PowerDesc in powerAll:
print (PowerNom, PowerDesc)


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')]

hero1 = Character("Klaitos")
hero1.ChoosePouvoirUnique()

im *WANT to display this* :

Froid devorant : Gele lenemi sur place
Flammes infernales : Embrase lenemi et le feu bruler

I don't know how to get this ? :(

2011/2/24 Steven D'Aprano 

> Alex Hall wrote:
>
>> On 2/24/11, 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)
>>>
>>
>  You need a __init__() function in this class, as with any class.
>>
>
> That's not strictly correct. You don't *need* an __init__ method, unless
> your class needs to be initialised. Most classes will, but some do not.
>
>
> [...]
>
>  Also, "for" should be lowercase, though I am
>> honestly not sure that this is a requirement(though I believe it is).
>>
>
> It certainly is. Python is case sensitive, so "for" and "FOR" and "For" are
> different. "for" is a Python keyword with special meaning. The others are
> just words with no special meaning.
>
>
>
>
> --
> Steven
>
> ___
> 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] having difficulty installing python

2011-02-24 Thread Mark Weil
Is there a reason you don't want to use the newer, already pre-installed
version?

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/python.1.html
___
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-24 Thread Alex Hall
On 2/24/11, Christopher Brookes  wrote:
> class Character:
>def __init__(self, name):
> self.name = name
>
> def ChoosePouvoirUnique(self):
> """ Permet de choisir le pouvoir unique du personnage """
> print ("Veuillez choisir votre pouvoir unique dans la liste")
>
>
> for PowerNom,PowerDesc in powerAll:
> print (PowerNom, PowerDesc)
>
>
> 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')]
>
> hero1 = Character("Klaitos")
> hero1.ChoosePouvoirUnique()
>
> im *WANT to display this* :
>
> Froid devorant : Gele lenemi sur place
> Flammes infernales : Embrase lenemi et le feu bruler
>
> I don't know how to get this ? :(
Again, what is the error (traceback) you get when you try to run the code?
>
> 2011/2/24 Steven D'Aprano 
>
>> Alex Hall wrote:
>>
>>> On 2/24/11, 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)

>>>
>>  You need a __init__() function in this class, as with any class.
>>>
>>
>> That's not strictly correct. You don't *need* an __init__ method, unless
>> your class needs to be initialised. Most classes will, but some do not.
>>
>>
>> [...]
>>
>>  Also, "for" should be lowercase, though I am
>>> honestly not sure that this is a requirement(though I believe it is).
>>>
>>
>> It certainly is. Python is case sensitive, so "for" and "FOR" and "For"
>> are
>> different. "for" is a Python keyword with special meaning. The others are
>> just words with no special meaning.
>>
>>
>>
>>
>> --
>> Steven
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Brookes Christopher.
>


-- 
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


Re: [Tutor] Display all field of a listuples

2011-02-24 Thread Alex Hall
On 2/24/11, Christopher Brookes  wrote:
> class Character:
>def __init__(self, name):
> self.name = name
>
> def ChoosePouvoirUnique(self):
> """ Permet de choisir le pouvoir unique du personnage """
> print ("Veuillez choisir votre pouvoir unique dans la liste")
>
>
> for PowerNom,PowerDesc in powerAll:
> print (PowerNom, PowerDesc)
>
>
> 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')]
>
> hero1 = Character("Klaitos")
> hero1.ChoosePouvoirUnique()
>
> im *WANT to display this* :
>
> Froid devorant : Gele lenemi sur place
> Flammes infernales : Embrase lenemi et le feu bruler
>
> I don't know how to get this ? :(
Again, what is the error (traceback) you get when you try to run the code?
>
> 2011/2/24 Steven D'Aprano 
>
>> Alex Hall wrote:
>>
>>> On 2/24/11, 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)

>>>
>>  You need a __init__() function in this class, as with any class.
>>>
>>
>> That's not strictly correct. You don't *need* an __init__ method, unless
>> your class needs to be initialised. Most classes will, but some do not.
>>
>>
>> [...]
>>
>>  Also, "for" should be lowercase, though I am
>>> honestly not sure that this is a requirement(though I believe it is).
>>>
>>
>> It certainly is. Python is case sensitive, so "for" and "FOR" and "For"
>> are
>> different. "for" is a Python keyword with special meaning. The others are
>> just words with no special meaning.
>>
>>
>>
>>
>> --
>> Steven
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Brookes Christopher.
>


-- 
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


Re: [Tutor] Help on Python Looping Please

2011-02-24 Thread Dave Angel

On 02/24/2011 11:55 AM, Walter Prins wrote:

On 24 February 2011 16:22, Dave Angel  wrote:



(Is there a reason you double-spaced all that code?  It makes it very hard
to read, and quite difficult to quote, since I had to delete every other
line.)



For what it's worth the code came out perfectly fine on my email reader
(GMail). (No double spacing, courier formatted, all in all pretty easy to
read. What email client are you using?)

Walter



I use Thunderbird 3.1.7 on Linux 10.04.  In text mode, naturally, but I 
get the same result in html mode.


The prose was properly spaced, and everyone else's messagesare properly 
spaced.  But the code in that particular message was double-spaced.



DaveA
___
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-24 Thread Alan Gauld

"Christopher Brookes"  wrote


class Character:
  def __init__(self, name):
   self.name = name

   def ChoosePouvoirUnique(self):
   """ Permet de choisir le pouvoir unique du personnage """
   print ("Veuillez choisir votre pouvoir unique dans la liste")
   for PowerNom,PowerDesc in powerAll:
   print (PowerNom, PowerDesc)


powerAll is a list of Power objects.
So you need to get each object then access the attributes
inside the object using dot notation:

for powerObject in powerAll:
   print "%s : %s" % (powerObject.name, powerObject.desc)


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')]

hero1 = Character("Klaitos")
hero1.ChoosePouvoirUnique()


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] Display all field of a listuples

2011-02-24 Thread Steven D'Aprano

Christopher Brookes wrote:


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')]



im *WANT to display this* :

Froid devorant : Gele lenemi sur place
Flammes infernales : Embrase lenemi et le feu bruler

I don't know how to get this ? :(


for pwr in powerAll:
print pwr.name, pwr.desc


If the order really matters to you, you need to sort powerAll into 
whatever order you prefer.






--
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-24 Thread Bill Allen
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.   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.   Not to mention, I thought it might
be a good learning opportunity.

--Bill








On Thu, Feb 24, 2011 at 03:00, Alan Gauld  wrote:

> "Bill Allen"  wrote
>
>
>  I know that I can use the following to get a listing of the environment of
>> my own system.   How can I do similar for another system on my network.
>> This is for administrative purposes.
>>
>
> Environments are user and process specific so you would need to
> access the remote machine, access the user account, connect
> to the specific process and then run the environment check.
>
> It rarely makes any sense unless its the user themselves
> doing the check.
>
> I assume there is a greater requirement at the bavk of this?
> What exactly is it you are trying to find out? There may be a better
> way.
>
> 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] accessing another system's environment

2011-02-24 Thread Steve Willoughby

On 24-Feb-11 19:30, 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



Are you sure you're talking about the same thing we are when you say 
"environment"?  There is no "the" environment on Unix-like systems. 
Every single process has its own environment.  Each user's login session 
loads their personal set of environment variables, which is inherited by 
the processes they launch, but can be modified from process to process.


Meanwhile, other users have their own environment, and system services 
have their own, etc.


I thought Windows was similar in this respect, isn't it?


computer management console.   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.   Not to mention, I
thought it might be a good learning opportunity.


Getting environment variables is easy if you can get your script to be 
executed in that environment.  Finding the environment of a running 
process can be done easily, too.  Look at the output of "ps" with 
certain options set, or the contents of files in /proc.  However, 
remember that there are as many environments are there are processes.

--
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] Display all field of a listuples

2011-02-24 Thread 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

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


[Tutor] list of dictionary

2011-02-24 Thread sunil tech
Hi all...

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...

Thank you in advance
___
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-24 Thread Pacific Morrowind

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 if applicable to your 
situation I'd suggest just doing for creation of the list

 d = []
(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:
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


Re: [Tutor] comparing strings

2011-02-24 Thread Edward Martinez

On 02/24/11 02:56, Dave Angel wrote:

On 01/-10/-28163 02:59 PM, Edward Martinez wrote:

On 02/23/11 19:29, Corey Richardson wrote:

On 02/23/2011 10:22 PM, Edward Martinez wrote:

Hi,

I'm new to the list and programming.
i have a question, why when i evaluate strings ie 'a'> '3' it reports
true, how does python come up with that?

Welcome! As far as I know, it compares the value of the ord()'s.


ord('a')

97

ord('3')

51

This is their number in the ASCII system. You can also do this:


chr(97)

'a'

chr(51)

'3'



A string is effectively an array of characters.  Each one may be ASCII 
or Unicode or other, depending partly on your Python version.


Each character has an ord() between 0 and 255, or between 0 and 65535. 
Except for some values below 0x20  (eg. tab, newline), these are 
printable.  So you can make a chart for your own system with a fairly 
simple loop.


Comparison is done left to right on the two strings, comparing one 
character at a time.  If there are no control characters, this 
approximates what a dictionary order would do.  But notice that all 
the capital letters appear before any of the lowercase characters. And 
that if you have accented characters, they're generally nowhere near 
the unaccented versions.


One other point:  if one string begins with all the characters in the 
other (eg. 'cat' and 'catatonic'), the longer string is then 
considered "greater".


DaveA


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

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