Re: [Tutor] Modify inherited methods

2010-04-28 Thread Walter Wefft

Steven D'Aprano wrote:
> And for guru-level mastery, replace to call to dict.__init__ with ... 
nothing at all, because dict.__init__ doesn't do anything.

>
>
>

(Sorry, should have sent to list).

I don't understand this - it must do something:

class MyDict1(dict):

   def __init__(self, *args, **kw):
   pass

class MyDict2(dict):

   def __init__(self, *args, **kw):
   dict.__init__(self, *args, **kw)


d = MyDict1(y=2)
print d
{}

d = MyDict2(y=2)
print d
{'y': 2}

d = MyDict1({'x': 3})
print d
{}

d = MyDict2({'x': 3})
print d
{'x': 3}

Behaviour is different depending on whether you call the superclass 
__init__ or not.


?


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


Re: [Tutor] (no subject)

2010-04-28 Thread Alan Gauld


"Marco Rompré"  wrote


Oups my posting was too big!!!


In general it is better to popst long listings (over 100 lines say)
to a web site such as pastebin. That will ensure they are readable
and will not fill up peoples mailboxes unnecessarily.

However, even better is to reproduce your error in a small sample
program so we do not have to read all of your code!


Why is none of my items button works In this, I have two files and in
my second file I imported all the function of the first one


I can't speak for all of them but the first one I looked at had an error,
very similar to that suggested by your error message.


self.afficher_item_bouton = Button(
self, text = "Modifier", fg = "blue", command =
self.modifier_item
)
self.afficher_item_bouton.pack(side = LEFT)



def afficher_item(self):
items = self.liste.curselection()
items = [self.app.modele.items[int(item)] for item in items]
if (items != []):
items = items[0]
itemsFrame = ItemsFrame(self, item)



In this code the method assigns a value to items, then reassigns items to a 
modified list.
If the list is not empty it reassigns items to the first element. It then 
creates a new variable.
passing a variable item which does bot exist in the method so shouldbe defined 
globally.
But your error message suggests it is not. I suspect the items[0] assignment 
should be

to item? Or maybe to self.item?


Here is my codes and my error code  for the two files please help me:
Traceback (most recent call last):


  File "F:\School\University\Session 4\Programmation
SIO\magasingolfvues.py", line 426, in 
app = App(racine, "magasinmodele.txt")
  File "F:\School\University\Session 4\Programmation
SIO\magasingolfvues.py", line 23, in __init__
ItemsFrame(contexte, item)
NameError: global name 'item' is not defined
>>>



--
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] Modify inherited methods

2010-04-28 Thread spir ☣
On Wed, 28 Apr 2010 07:53:06 +0100
Walter Wefft  wrote:

> Steven D'Aprano wrote:
>  > And for guru-level mastery, replace to call to dict.__init__ with ... 
> nothing at all, because dict.__init__ doesn't do anything.
>  >
>  >
>  >
> 
> (Sorry, should have sent to list).
> 
> I don't understand this - it must do something:
> 
> class MyDict1(dict):
> 
> def __init__(self, *args, **kw):
> pass
> 
> class MyDict2(dict):
> 
> def __init__(self, *args, **kw):
> dict.__init__(self, *args, **kw)
> 
> 
> d = MyDict1(y=2)
> print d
> {}
> 
> d = MyDict2(y=2)
> print d
> {'y': 2}
> 
> d = MyDict1({'x': 3})
> print d
> {}
> 
> d = MyDict2({'x': 3})
> print d
> {'x': 3}
> 
> Behaviour is different depending on whether you call the superclass 
> __init__ or not.
> 
> ?

Hem... this is a rather obscure point (I personly have it wrong each time I 
need to subtype builtin types). Maybe you find some enlightenment in the 
following code:

===
class MyDict0(dict):
pass
class MyDict1(dict):
def __init__(self, *args, **kw):
pass
class MyDict2(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
===

d0 = MyDict0(a=1) ; d1 = MyDict1(a=1) ; d2 = MyDict2(a=1)
print d0,d1,d2 # ==> {'a': 1} {} {'a': 1}

In case you do not define any custom __init__ *at all*, dict will transparently 
feed an instance of your type with provided entries, if any. If you define one, 
and don't feed the collection yourself, you need to call dict's __init__ to do 
it for you.
This behaviour allows having custom params at init:

===
class MyDict(dict):
def __init__(self, name="", **entries):
self.name = name
dict.__init__(self, **entries)
def __str__(self):
return "%s:%s" %(self.name,dict.__str__(self))
d = MyDict(name="XYZ", a=1,b=2,c=3)
print d # ==> XYZ:{'a': 1, 'c': 3, 'b': 2}
===

But all this does not apply to "atomic" builtin types such as int:

===
class MyInt0(int):
pass

class MyInt1(int):
def __init__(self, *args):
pass

class MyInt2(int):
def __init__(self, *args):
int.__init__(self, *args)

i0 = MyInt0(1) ; i1 = MyInt1(1) ; i2 = MyInt2(1)
print i0,i1,i2  # ==> 1 1 1
===

This runs by me with a message from the compiler: "DeprecationWarning: 
object.__init__() takes no parameters" (about the call to int.__init__).
I would like to understand the implementation and the reason for this 
difference.
This means one cannot customize the initialisation of a subtype of int like is 
done above for a subtype of dict:

===
class MyInt(int):
def __init__(self, value=0, name=""):
self.name = name
int.__init__(self, value)
def __str__(self):
return "%s:%s" %(self.name,int.__str__(self))
#~ i = MyInt(name="XYZ", value=3)
i = MyInt(3, "XYZ")
print i # ==> TypeError: an integer is required
===

(Keyword parameters will also be rejected.) This is due to the implicit 
execution of the builtin constructor, which requires definite parameters (here 
a value and possibly a base).
More info on this topic welcome :-)

Denis


vit esse estrany ☣

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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Walter Wefft

spir ☣ wrote:

On Wed, 28 Apr 2010 07:53:06 +0100
Walter Wefft  wrote:


Steven D'Aprano wrote:
 > And for guru-level mastery, replace to call to dict.__init__ with ... 
nothing at all, because dict.__init__ doesn't do anything.

 >
 >
 >

(Sorry, should have sent to list).

I don't understand this - it must do something:

class MyDict1(dict):

def __init__(self, *args, **kw):
pass

class MyDict2(dict):

def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)


d = MyDict1(y=2)
print d
{}

d = MyDict2(y=2)
print d
{'y': 2}

d = MyDict1({'x': 3})
print d
{}

d = MyDict2({'x': 3})
print d
{'x': 3}

Behaviour is different depending on whether you call the superclass 
__init__ or not.


?


Hem... this is a rather obscure point (I personly have it wrong each time I 
need to subtype builtin types). Maybe you find some enlightenment in the 
following code:

===
class MyDict0(dict):
pass
class MyDict1(dict):
def __init__(self, *args, **kw):
pass
class MyDict2(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
===

d0 = MyDict0(a=1) ; d1 = MyDict1(a=1) ; d2 = MyDict2(a=1)
print d0,d1,d2 # ==> {'a': 1} {} {'a': 1}



You reiterate my point. To say that dict.__init__ can be omitted in a 
subclass's __init__ with no effect, is not a correct statement.


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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Steven D'Aprano
On Wed, 28 Apr 2010 04:53:06 pm Walter Wefft wrote:
> Steven D'Aprano wrote:
>  > And for guru-level mastery, replace to call to dict.__init__ with
>  > ...
>
> nothing at all, because dict.__init__ doesn't do anything.
[...]
> Behaviour is different depending on whether you call the superclass
> __init__ or not.
>
> ?

Fascinating... it seems that you are correct. Just goes to show, you can 
be programming in Python for well over a decade and still learn 
something new.

Believe it or not, I did test the behaviour before posting, but 
obviously my tests were faulty!


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


Re: [Tutor] Using Regex to produce text

2010-04-28 Thread mhw
While some patterns are infinite, other's aren't (e.g. The example I gave). 

Using a subset of Regex syntax to produce a set of strings has the advantage of 
using a well understood and documented form, and if you could hook into the 
existing API, at minimal coding effort.

In addition, it allows a nice symmetry between search and production of 
resource names.

E.g.

Source some data (containing resources)
Label res 1 to res n using re.pattern(p1) 
Add this data to the larger data lump

 do some stuff...

Find the data items you had again:
DataGroup1 = AllData.search(re.pattern(p1))

I suspect it's not that easy, as I don't think we can get to the internals of 
the regex FSM. However, I thought it would be worth asking.

Matt
Etc.


--Original Message--
From: Luke Paireepinart
To: m...@doctors.net.uk
Cc: Python tutor
Subject: Re: [Tutor] Using Regex to produce text
Sent: 28 Apr 2010 07:51

On Wed, Apr 28, 2010 at 1:27 AM,   wrote:
> Dear All,
>
> Quick question:
>
> Is there an way of using the regex patterns to produce text, instead of 
> matching it?
>
> E.g.:
> pat = re.compile("ab?d")
> pat.getListofPossibleText()
>

There's no end to the length of many patterns so this would be fairly pointless.
For example, what would getListofPossibleText do for the pattern ".*" ?

I think the better question is: what are you trying to do?
Or perhaps: Why do you think you need to solve your problem this way?

-Luke


Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Emile van Sebille

On 4/28/2010 3:20 AM Walter Wefft said...

spir ☣ wrote:

On Wed, 28 Apr 2010 07:53:06 +0100
Walter Wefft  wrote:



===
class MyDict0(dict):
pass
class MyDict1(dict):
def __init__(self, *args, **kw):
pass
class MyDict2(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
===

d0 = MyDict0(a=1) ; d1 = MyDict1(a=1) ; d2 = MyDict2(a=1)
print d0,d1,d2 # ==> {'a': 1} {} {'a': 1}



You reiterate my point. To say that dict.__init__ can be omitted in a
subclass's __init__ with no effect, is not a correct statement.



It wasn't the omitted case that exhibits the difference.  When 
sub-classing, any methods omitted defer to the parent's version so the 
init from the dict parent happened.


Emile

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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Walter Wefft

Emile van Sebille wrote:

On 4/28/2010 3:20 AM Walter Wefft said...

spir ☣ wrote:

On Wed, 28 Apr 2010 07:53:06 +0100
Walter Wefft  wrote:



===
class MyDict0(dict):
pass
class MyDict1(dict):
def __init__(self, *args, **kw):
pass
class MyDict2(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
===

d0 = MyDict0(a=1) ; d1 = MyDict1(a=1) ; d2 = MyDict2(a=1)
print d0,d1,d2 # ==> {'a': 1} {} {'a': 1}



You reiterate my point. To say that dict.__init__ can be omitted in a
subclass's __init__ with no effect, is not a correct statement.



It wasn't the omitted case that exhibits the difference.  When 
sub-classing, any methods omitted defer to the parent's version so the 
init from the dict parent happened.




"omitted in a subclass's __init__", ie. a *call* to the superclass's method

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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Emile van Sebille

On 4/28/2010 9:32 AM Walter Wefft said...

Emile van Sebille wrote:

On 4/28/2010 3:20 AM Walter Wefft said...

You reiterate my point. To say that dict.__init__ can be omitted in a
subclass's __init__ with no effect, is not a correct statement.



It wasn't the omitted case that exhibits the difference. When
sub-classing, any methods omitted defer to the parent's version so the
init from the dict parent happened.



"omitted in a subclass's __init__", ie. a *call* to the superclass's method



You're right.  Failure to read on my part.  Sorry.

Emile

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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Eike Welk
On Wednesday April 28 2010 13:04:30 Steven D'Aprano wrote:
> On Wed, 28 Apr 2010 04:53:06 pm Walter Wefft wrote:
> > Steven D'Aprano wrote:
> >  > And for guru-level mastery, replace to call to dict.__init__ with
> >  > ...
> >
> > nothing at all, because dict.__init__ doesn't do anything.
> 
> [...]
> 
> > Behaviour is different depending on whether you call the superclass
> > __init__ or not.
> >
> > ?
> 
> Fascinating... it seems that you are correct. Just goes to show, you can
> be programming in Python for well over a decade and still learn
> something new.

You probably thought of tuple, where __init__ really does nothing. Tuple 
instances are created by __new__.


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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread C M Caine
Thank you all. One tangentially related question: what does (self,
*args, **kwargs) actually mean? How does one reference variables given
to a function that accepts these inputs?

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


[Tutor] Python beginner having troubles understanding word lists and character lists

2010-04-28 Thread Daniel
Hello, I'm a beginner programmer, trying to learn python. I'm currently
reading The programming Historian,
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
I stumbled into lists of words and lists of characters. I have no
explications in that book for those two and I didn't found some explications
on the web. Could you point me to a link or something where I can read about
them? I don't seem to understand why they are used.
thank you so much!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python beginner having troubles understanding word lists and character lists

2010-04-28 Thread Luke Paireepinart
On Wed, Apr 28, 2010 at 2:06 PM, Daniel  wrote:
> Hello, I'm a beginner programmer, trying to learn python. I'm currently
> reading The programming
> Historian,http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
> I stumbled into lists of words and lists of characters. I have no
> explications in that book for those two and I didn't found some explications
> on the web. Could you point me to a link or something where I can read about
> them? I don't seem to understand why they are used.
> thank you so much!
>

Daniel,
I'm not too clear on what you're talking about.
What part is confusing you exactly?
Could you provide a code example?
Thanks,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Regex to produce text

2010-04-28 Thread Lie Ryan
On 04/29/10 01:32, m...@doctors.net.uk wrote:
> While some patterns are infinite, other's aren't (e.g. The example I gave). 

How should the regex engine know about that?

> Using a subset of Regex syntax to produce a set of strings has the 
> advantage of using a well understood and documented form, and if you
> could hook into the existing API, at minimal coding effort.

> In addition, it allows a nice symmetry between search and production of 
> resource names.

String generation is generally simpler than string parsing. If the
pattern of the string you're generating is so complex that you need a
regex-powered name generator, it will probably be impossible to parse
that. Use string interpolation/formatting instead: '%s_%0s.txt' % (name,
num)

> I suspect it's not that easy, as I don't think we can get to the internals of
> the regex FSM. However, I thought it would be worth asking.

The problem is how you would define the "universe" set of characters. If
you had a '.', would you want alphanumeric only, all printable
characters, all ASCII (0-127) characters, all byte (0-255) character,
all Unicode characters? It's too ambiguous and if you say to follow what
regex is doing, then regex just happen to not be choosing the most
convenient default for pattern generators.

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


Re: [Tutor] Modify inherited methods

2010-04-28 Thread Eike Welk
On Wednesday April 28 2010 20:57:27 C M Caine wrote:
> Thank you all. One tangentially related question: what does (self,
> *args, **kwargs) actually mean? How does one reference variables given
> to a function that accepts these inputs?

*args is a tuple containing the positional arguments; 
**kwargs is a dictionary which contains the keyword arguments. 

The stars before the variable names are the special syntax to handle arbitrary 
function arguments; you can use any variable names you want. You can use the 
syntax in a function call and in a function definition.

Here's an example session with Ipython:

In [5]: def foo(*args, **kwargs):
   ...: print "args: ", args
   ...: print "kwargs: ", kwargs
   ...:
   ...:

In [6]: foo(1, 2, 3)
args:  (1, 2, 3)
kwargs:  {}

In [7]: foo(1, 2, 3, a=4, b=5)
args:  (1, 2, 3)
kwargs:  {'a': 4, 'b': 5}

In [8]: foo( *(10, 11), **{"p":20, "q":21})
args:  (10, 11)
kwargs:  {'q': 21, 'p': 20}


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


Re: [Tutor] Using Regex to produce text

2010-04-28 Thread Jerry Hill
On Wed, Apr 28, 2010 at 2:27 AM,   wrote:
> Is there an way of using the regex patterns to produce text, instead of 
> matching it?

There have been some previous discussions about generating all of the
possible matches for a given regular expressions.  I believe these are
the first messages in a couple of recent threads on python-list:

http://mail.python.org/pipermail/python-list/2010-February/1235120.html
http://mail.python.org/pipermail/python-list/2010-March/1240605.html

There's at least one sample implementation using the pyparsing library here:
http://pyparsing.wikispaces.com/file/view/invRegex.py

This message appears to have another implementation, sent to the list
as attachments:
http://mail.python.org/pipermail/python-list/2010-April/1240687.html

I haven't tried any of them myself, but they may be useful to you if
you really need to go down this road.

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


Re: [Tutor] Using Regex to produce text

2010-04-28 Thread Steven D'Aprano
On Thu, 29 Apr 2010 06:36:18 am Lie Ryan wrote:
> On 04/29/10 01:32, m...@doctors.net.uk wrote:
> > While some patterns are infinite, other's aren't (e.g. The example
> > I gave).
>
> How should the regex engine know about that?

The regex engine itself doesn't run in reverse, so it can't know this 
and doesn't need to. However, it is possible to write a reverse regex 
engine which does run in reverse, in which case it is up to the 
programmer who creates it to encode that knowledge in the engine.


> > Using a subset of Regex syntax to produce a set of strings has the
> > advantage of using a well understood and documented form, and if
> > you could hook into the existing API, at minimal coding effort.
> >
> > In addition, it allows a nice symmetry between search and
> > production of resource names.
>
> String generation is generally simpler than string parsing. If the
> pattern of the string you're generating is so complex that you need a
> regex-powered name generator, it will probably be impossible to parse
> that. 

What? That makes no sense. That's like saying "I have here a formula for 
generating a series of numbers which is so complicated that it is 
impossible to write a formula for it". Since the string was generated 
from a regex, it will be parsable by *exactly* the same regex.


> Use string interpolation/formatting instead: '%s_%0s.txt' % 
> (name, num)

All this does is delay the work. You still have to generate all possible 
names and nums. Since you haven't defined what they are meant to be, 
it's impossible to do so.


> > I suspect it's not that easy, as I don't think we can get to the
> > internals of the regex FSM. However, I thought it would be worth
> > asking.
>
> The problem is how you would define the "universe" set of characters.

The same way the regex engine does.


> If you had a '.', would you want alphanumeric only, all printable
> characters, all ASCII (0-127) characters, all byte (0-255) character,
> all Unicode characters? 

The regex engine defines . as meaning "any character except newline, or 
any character including newline if the dotall flag is given". The regex 
engine operates on byte strings unless you give it the unicode flag. 
Given that the original poster wants to stick to regex syntax rather 
than learn a different syntax with different definitions, then the 
universal set of characters is well defined.

Here is a generator which should do the job:

# Untested.
def gen_dot(dotall_flag=False, unicode_flag=False):
"""Iterate over the sequence of strings which matches ."""
if not unicode_flag:
all_chars = [chr(i) for i in range(256)]
if not dotall_flag:
all_chars.remove('\n')
for c in all_chars:
yield c
else:
# There are a *lot* of unicode characters, but I don't know
# how many. Take the coward's way out.
raise NotImplementedError('left as an exercise for the reader')




> It's too ambiguous and if you say to follow 
> what regex is doing, then regex just happen to not be choosing the
> most convenient default for pattern generators.

Whether regex rules are the most convenient, or whether learning yet 
another complicated, terse language is better, is not the question.



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


[Tutor] date problems

2010-04-28 Thread Eric Meigs

I want to create a program to tell me when I am supposed to do things.
I have a text file with dates like  4-4-2010' as well as other data. I 
want to read in this date into my code and then compare it with 
'date.today()'

example 'if /variable/ >= today:'
I don't see how to read in a string and get it into a format for comparison.

I can do all of the other code.

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


Re: [Tutor] date problems

2010-04-28 Thread Alan Gauld


"Eric Meigs"  wrote 


I don't see how to read in a string and get it into a format for comparison.


Have you loked at the time and datetime modules?
They should do all you need.


--
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] Python beginner having troubles understanding word listsand character lists

2010-04-28 Thread Alan Gauld


"Daniel"  wrote 


I stumbled into lists of words and lists of characters. I have no
explications in that book for those two and I didn't found some explications
on the web. 


aListOfWords = ['one','word','or','many']
aListOfCharacters = ['a','s','d','f']

aStringOfCharacters = 'asdf'
aWord = aStringOfCharacters

Now what part do you not understand?


Could you point me to a link or something where I can read about
them? I don't seem to understand why they are used.


You use a list of words any time you want to process multiple words. 
For example a spelling checker may break a document into a list 
of words and compare each word to a reference list of correctly 
spelled words.


A list of characters is rarely used in Python since you can use 
a string in almost every case. 

You will find some more information in the "Raw Materials" topic 
of my tutorial.


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] Python beginner having troubles understanding word lists and character lists

2010-04-28 Thread Steven D'Aprano
On Thu, 29 Apr 2010 05:06:22 am Daniel wrote:
> Hello, I'm a beginner programmer, trying to learn python. I'm
> currently reading The programming Historian,
> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
> I stumbled into lists of words and lists of characters. I have no
> explications in that book for those two and I didn't found some
> explications on the web. Could you point me to a link or something
> where I can read about them? I don't seem to understand why they are
> used.
> thank you so much!

Hi Daniel,

Is English your first language? I ask because "list of words" is 
ordinary English, and the meaning in Python is hardly different.

In English, a list of words is a collection of words. There is no 
official way of writing a list in English. Here are three examples:

red blue yellow green

milk
money
mud
monkeys
moose

king, queen, emperor, peasant, duke, serf


In Python, a word is just a string with no spaces inside it:

"word"
"not a word"

and a list can be created with square brackets and commas:

["red", "blue", "yellow", "green"]


Characters are single letters, digits or punctuation marks:

a e i o u 2 4 6 8 . ? $ %

In Python, characters are just strings, and you can put them in a list:

["a", "e", "i", "o", "u", "2", "4", "6", "8", ".", "?", "$", "%"]


Hope this helps you.



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


Re: [Tutor] date problems

2010-04-28 Thread Alex Clark
On 2010-04-28, Eric Meigs  wrote:
> This is a multi-part message in MIME format.
> --===0277013919==
> Content-Type: multipart/alternative;
>   boundary="060806000801070600050409"
>
> This is a multi-part message in MIME format.
> --060806000801070600050409
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> Content-Transfer-Encoding: 7bit
>
> I want to create a program to tell me when I am supposed to do things.
> I have a text file with dates like  4-4-2010' as well as other data. I 
> want to read in this date into my code and then compare it with 
> 'date.today()'
> example 'if /variable/ >= today:'
> I don't see how to read in a string and get it into a format for comparison.

So you have two questions here, one "how to read in a string" and two "get it 
into a format for comparison"?

It seems to me you could do something like this:

from datetime import datetime

input = open('dates.txt','rb')
list = input.read()
dates = list.split()[0] # chars before the first whitespace 
items = list.split()[-1] # everything after the first whitespace

if datetime.now().strftime('%m-%d-%Y') == dates:
print 'Do %s today!' % items

(from http://github.com/aclark4life/Python-Tutor/blob/master/eric-meigs.py)

> I can do all of the other code.
>
> Eric
>
> --060806000801070600050409
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
>
>
>
>
>
>
>
>
>I want to create a program to tell
> me when I am supposed to do things.
> I have a text file with dates like  4-4-2010' as well as other data. I
> want to read in this date into my code and then compare it with
> 'date.today()' 
> example 'if variable >= today:' 
> I don't see how to read in a string and get it into a format for
> comparison.
>
> I can do all of the other code.
>
> Eric
>
>
>
>
> --060806000801070600050409--
>
> --===0277013919==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> --===0277013919==--
>


-- 
Alex Clark · http://aclark.net
Author of Plone 3.3 Site Administration · http://aclark.net/plone-site-admin

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