Re: Enumerating words and Adding integer, character and string

From: Jon-Pierre Gentil (jgentil_at_sebistar.net)
Date: 03/06/04


Date: Fri, 05 Mar 2004 23:20:01 -0600
To: dont bother <dontbotherworld@yahoo.com>


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@jabber.org




Relevant Pages


Loading