Enumerating words and Adding integer, character and string

Jon-Pierre Gentil jgentil at sebistar.net
Sat Mar 6 00:20:01 EST 2004


On Fri, 2004-03-05 at 21:15, dont bother wrote:

> 1. How do I make a vector of words in a file.
> Ex:
> File has 
> 
> Alpha
> Beta 
> Gamma
> 
> I want to have this file:
> 1 Alpha
> 2 Beta
> 3 Gamma
> 
> I just dont want to write it/print it instead I want a
> mapping. A vector kind of thing whose first attribute
> is interger second is the 'word'

f = open("filename", "r")
for l in f:
    print l

> 2. How to I create a string for example by adding:
> 
> s=1 + ":" + "dont"
> 
> this does not work if I normally try to concatenate
> and write to a file.

s = string(1) + ":" + "dont"

Remember that even though variables have no type declaration, Python is
a strongly-typed language.  Adding a string to an integer just doesn't
work, the integer.

-- 
Jon-Pierre Gentil      :   PGP Key ID 0xA21BC30E
    AIM: Zenethian     :   Jabber: zenethian at jabber.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20040305/0c0eda64/attachment.sig>


More information about the Python-list mailing list