[Tutor] handling a textfile continued

2009-08-19 Thread Olli Virta
Hi!

Sorry. OK I admit I might have been confusing. Although I got some good
ideas from the messages. Thanks.

Let me try again:

So I got this big textfile. It's full of data from a database. About 200 or
more rows or lines in a textfile.
There's three first rows that belong to the same subject. And then next
three rows belong to another subject and so on, to the end of the file.

What I need to do, is put the three rows that goes together and belong to
certain subject, on a one single line in the output textfile.
And that goes with the rest of the data to the end of the new file.

Thanks. OV
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help on input error

2009-08-19 Thread Luke Paireepinart
Please reply to the whole list, using Reply All, rather than directly to me
or anyone else, unless you want the conversation to take place off-list
(unless you have a good reason to do so, we discourage this, because then
future people cannot benefit from our advice.)  Kent has already indicated
the issue, you are not putting your modules in the proper location.

On Wed, Aug 19, 2009 at 9:22 PM,  wrote:

> Yes, I can import standard library modules.
>
> - Original Message -
> From: "Luke Paireepinart" 
> To: "David Shunick" 
> Cc: tutor@python.org
> Sent: Wednesday, August 19, 2009 6:02:42 PM GMT -08:00 US/Canada Pacific
> Subject: Re: [Tutor] Help on input error
>
> Can you import other (Standard library) modules?  or can you not import
> anything?
>
> On Wed, Aug 19, 2009 at 6:14 PM, David Shunick wrote:
>
>>  I'm trying to learn Python, but keep running into the erroor message
>> ImportError: no module named area.
>>
>> I created a file area.py in IDLE. I'm using Python 3.1 and Window XP.
>> After saving the file in c:/Python31/Lib/Python  Modules/area.py
>>
>> I can run the program using F5. But when I start a new shell, and enter 
>> *import
>> area, *that's when I get the error message. And it's not just this
>> program.I have the same problem with all that I try to import.
>>
>> I hope someone  can help!
>>
>> Dave
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help on input error

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 7:14 PM, David Shunick wrote:
> I'm trying to learn Python, but keep running into the erroor message
> ImportError: no module named area.
>
> I created a file area.py in IDLE. I'm using Python 3.1 and Window XP. After
> saving the file in c:/Python31/Lib/Python  Modules/area.py
>
> I can run the program using F5. But when I start a new shell, and enter
> import area, that's when I get the error message. And it's not just this
> program.I have the same problem with all that I try to import.


"Python Modules" is not a folder recognized by Python. Try putting the
file in Python31/Lib/site-packages/area.py

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help on input error

2009-08-19 Thread Luke Paireepinart
Can you import other (Standard library) modules?  or can you not import
anything?

On Wed, Aug 19, 2009 at 6:14 PM, David Shunick  wrote:

>  I'm trying to learn Python, but keep running into the erroor message
> ImportError: no module named area.
>
> I created a file area.py in IDLE. I'm using Python 3.1 and Window XP. After
> saving the file in c:/Python31/Lib/Python  Modules/area.py
>
> I can run the program using F5. But when I start a new shell, and enter 
> *import
> area, *that's when I get the error message. And it's not just this
> program.I have the same problem with all that I try to import.
>
> I hope someone  can help!
>
> Dave
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help on input error

2009-08-19 Thread David Shunick
I'm trying to learn Python, but keep running into the erroor message 
ImportError: no module named area.

I created a file area.py in IDLE. I'm using Python 3.1 and Window XP. After 
saving the file in c:/Python31/Lib/Python  Modules/area.py

I can run the program using F5. But when I start a new shell, and enter import 
area, that's when I get the error message. And it's not just this program.I 
have the same problem with all that I try to import.

I hope someone  can help!

Dave___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Possible bug in django models when assigning model attribute

2009-08-19 Thread Glen Zangirolami
I ran into something weird in Django and i'm completely stumped. I got it to
work but i'm trying to understand the logic behind it.
*I have the following data model:*

from django.db import models

class Setting(models.Model):
name  = models.CharField(max_length=200)
value = models.TextField()

class Meta:
db_table = "t_settings"

def __unicode__(self):
return self.name

*I have the following form model:*

from django import forms

class GlobalSettingsForm(forms.Form):
# specify all the variables here
site_name = forms.CharField(required=True,
max_length=200,
label="Site Name",
help_text="What you want your site to be
called company name, personal name, etc."
)

site_tagline = forms.CharField(required=False,
   max_length=200,
   label="Site Tagline",
   help_text="A quick tag line on what your
site is about")

site_url = forms.URLField(required=True,
  label="Site URL",
  max_length=200,
  help_text="All links that reference your site
will use this url. I would not change this unless you are super sure." )



>From the shell I have the following code to create the form:

form = GlobalSettingsForm(data={'site_name':'test','site_url':'
http://localhost/','site_tagline':'test'})

Running a type on form i get: 
, perfect so far...

next I call form.is_valid() to get the cleaned_data attribute and all is
good.

form.cleaned_data returns {'site_name': u'test', 'site_tagline': u'test',
'site_url': u'http://localhost/'} as expected

now i want to change the information in the database so I loop through
cleaned_data, grab the object, and save:

for item in form.cleaned_data:
*setting = Setting.objects.filter(name=item)*
setting[0].value = form.cleaned_data[item]
setting[0].save()

but it *does not work*. setting[0].value = form.cleaned_data[item] fails to
assign the data

if i run it like this it works:

for item in form.cleaned_data:
*setting = Setting.objects.get(name__exact=item)*
setting.value = form.cleaned_data[item]
setting.save()

all i did was change the method used from filter to get, why does one work
and not the other??

if i create the objects individually and equate them they are the same:
setting = Setting.objects.get(name__exact=item)
setting2 = Setting.objects.filter(name=item)

setting2[0] == setting it equals True
type(setting2[0]) == setting it equals True

Also I am using, Django 1.1 with MySql Python...

Stumped.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 4:37 PM, Jramak wrote:
> I
> also looked at virtualenv http://pypi.python.org/pypi/virtualenv . Each
> virtual env takes up 2.3 MB. To me this seems a bit of overkill, but this
> will enable you to run Python24, Python25, Python26 etc specific code on one
> computer.

You don't need virtualenv to run different versions of Python on one
computer, just specify which interpreter you want to use to run a
script.

By default virtualenv copies your site-packages directory to each
virtual environment, that is probably the bulk of the 2.3 MB. Disable
the copy with the --no-site-packages option. Of course you will then
have to install any needed modules yourself.
http://pypi.python.org/pypi/virtualenv#the-no-site-packages-option

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 4:41 PM, Jramak wrote:
>>
>> Sorry, I mean put the packages in the same directory as the python
>> script that needs them. The search path is sys.path which is affected
>> by PYTHONPATH among other things...
>>
>>
>
>
> sys.path is affected by PYTHONPATH ? how could it be affected by the
> PYTHONPATH ?

sys.path is the actual, runtime module search path. When Python is
started, it initialized sys.path from a variety of sources including
predefined locations, the contents of PYTHONPATH, and any .pth files
found.

http://docs.python.org/tutorial/modules.html#the-module-search-path

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Jramak
>
>
> Sorry, I mean put the packages in the same directory as the python
> script that needs them. The search path is sys.path which is affected
> by PYTHONPATH among other things...
>
>
>

sys.path is affected by PYTHONPATH ? how could it be affected by the
PYTHONPATH ?

Could you pls enlighten me ?

Jramak
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Jramak
 Thanks for all the insight, everyone.

I was originally thinking of writing a bash or bat script that would set the
PYTHONPATH and other environment variables before running the specific
application code. It seemed to be the most simplest solution. There are no
other applications that rely on the PYTHONPATH. As Alan said this might
result in surprises

So a combo solution where in the env vars would be in an .ini file and the
path is set in sys.path would be, IMHO a good way to go.. it's simple. I
also looked at virtualenv http://pypi.python.org/pypi/virtualenv . Each
virtual env takes up 2.3 MB. To me this seems a bit of overkill, but this
will enable you to run Python24, Python25, Python26 etc specific code on one
computer.
Jramak
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 4:00 PM, Jramak wrote:

>> One more - put required packages and modules into the same directory
>> as the executable, usually the current directory is on the Python
>> search path.
>>
>> Kent
>
>
> Hi Kent, there is no executable. It is just a collection of python scripts.
> I assume you refer to the Python search path as PYTHONPATH or sys.path. Do
> correct me if I am wrong.

Sorry, I mean put the packages in the same directory as the python
script that needs them. The search path is sys.path which is affected
by PYTHONPATH among other things...

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 3:56 PM, Jramak wrote:
>>
>>
>> Don't edit site.py, it is part of the std lib. If you do want to
>> customize it, add a site-customize.py in your site-packages folder and
>> put your customizations there.
>
> There is no site-customize.py in Python25, how does Python know that
> site-customize.py needs to be loaded on start-up? Or did you mean
> sitecustomize.py ?

Yes, sitecustomize.py.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Jramak
>
>
>>
>> Don't edit site.py, it is part of the std lib. If you do want to
>> customize it, add a site-customize.py in your site-packages folder and
>> put your customizations there.
>
>

>
>> There is no site-customize.py in Python25, how does Python know that
> site-customize.py needs to be loaded on start-up? Or did you mean
> sitecustomize.py ?
>
> Jramak
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Jramak
>
>
>
>
> Don't edit site.py, it is part of the std lib. If you do want to
> customize it, add a site-customize.py in your site-packages folder and
> put your customizations there.
>
> Kent
>


There is no site-customize.py in Python25, how does Python know that
site-customize.py needs to be loaded on start-up? Or did you mean
sitecustomize.py ?

Jramak
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Jramak
>
>
> One more - put required packages and modules into the same directory
> as the executable, usually the current directory is on the Python
> search path.
>
> Kent
>

Hi Kent, there is no executable. It is just a collection of python scripts.
I assume you refer to the Python search path as PYTHONPATH or sys.path. Do
correct me if I am wrong.

Jramak
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2009-08-19 Thread Luke Paireepinart
How are you running it?This usually happens when you have an error in your
connection, and then you try to re-run it, and the previous connection
attempt has not released the port yet.
Are you having an error between subsequent runs, or do you have an error the
first time you run it after a fresh reboot?

On Wed, Aug 19, 2009 at 6:32 AM, Rayon  wrote:

>  using python telnet lib to connect to a Nortel switch, and dump some
> tables.
> My problem is that every now and then the connection is reset by peer .
> Telnet Error : (10054, Connection reset by peer)
> I need  to know why, I have it in a loop so it will download after a few
> tries but I need to know why.
> here is the code.
>
>
> #main telnet class
> import telnetlib
> #import telnet lib
>
> class supertelnet: # super tenet class
>
>
> def __init__(self): # def construct
> ""
>
> def telNetCall(self, Host, User, Pass, LocalFile):
> print "start lens dump"
> host  = Host
> user  = User
> password = Pass
> file = LocalFile
> telnet  = telnetlib.Telnet(host) # connect to telnet client
> #telnet.set_debuglevel(1)
> telnet.read_until('Enter User Name', 3) # read session data untill
> match or timeout.
> telnet.write(user + '\r') # send username
> telnet.write(password + '\r') #send password
> # send command to dump len files
> # start
> print "lens dump in progress"
> telnet.write('table ibnlines' + '\r')
> telnet.write('format pack' + '\r')
> telnet.write('list all' + '\r')
> telnet.write('logout' + '\r')
> #end of commands
> lens =  telnet.read_all() # get session data and store data
> print "file write strated"
> x = open(file,'wd') # open file
> x.write(lens) # write data to file
> print "file done"
>
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] handling a textfile

2009-08-19 Thread Dave Angel

Alan Gauld wrote:


"Olli Virta"  wrote

I have a textfile (job.txt) that needs modifying. The structure of 
this file

is like this:

AAA1...
BBB1...
CCC1...
AAA2...
BBB2...
CCC2...
etc...
Question is how can I turn this all to a textfile (done.txt) that is 
suppose

to look like this:

AAA1...BBB1...CCC1...
AAA2...BBB2...CCC2...


Lots of ways to do it. The simplest is to read the variables line by 
line,

so, in pseudo code:

while infile not empty
a = f.readline()
b = f.readline()
c = f.readline()
outfile.write("%s,%s,%s" % (a,b,c) )

If the data is manageable you could read it all into a list then use list
slicing to achieve the same

data = infile.readlines()
for start in range(len(data))[::3]:  # get every third index
outfile.write("%s\t%s\t%s" % tuple(data[start :start+3]) )

I suspect you can do even clever things with itertools using groupby
and such, but I'm no itertools expert - its on my list of things to 
learn... :-)


HTH,

Between ellipses and etc., you've managed to confuse everyone with the 
actual format of your file.


But Alan's response is the closest so far to what I think you might have 
had in mind.  The thing he seems to be missing is the treatment of newlines.


Basically your output file is just like your input file except that some 
newlines have been removed.  So the only question is what's the pattern 
of removal.  You might have a constant number of input lines per group 
(e.g. three for your present example).  If that's the case, you want to 
strip off all newlines except those in front of a multiple of (3).   So 
loop through the data array, using rstrip() on all the lines except 2, 
5, 8, ...   You can use the modulo operator (%) to decide whether an 
index has the right form.


Alternatively, you might be saying you want a newline whenever the 
prefix of the line changes.  So loop through the lines, doing the 
rstrip() unless the next line begins the same as the present one.


DaveA






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] handling a textfile

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 5:54 AM, Alan Gauld wrote:

> Lots of ways to do it. The simplest is to read the variables line by line,
> so, in pseudo code:
>
> while infile not empty
>    a = f.readline()
>    b = f.readline()
>    c = f.readline()
>    outfile.write("%s,%s,%s" % (a,b,c) )

You will need to strip newlines from a and b.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question if my reasoning is right

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 1:52 AM, Darth Kaboda wrote:
> I'm questioning my reason for why the follwoing code doesn't behave as I
> thought it would upon first coding a project.
>
> m = 8
> n = 10
> cb = [[[0, None]] * (n + 1)] * (m + 1)
> cb[3][2][0] = 10
>
> This last statement causes the every first element in the list to update. Is
> this becuase this method of initializing a list is just a copy of the same
> list in memory?

Not literally a copy, but pointing to the same list. The correct term
is that each element of the list is a reference, or alias, to the same
list.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Kent Johnson
On Tue, Aug 18, 2009 at 7:57 PM, Jramak wrote:
> Hello
> We have developed three custom applications in Python. Each one of
> these applications needs a different PYTHONPATH, in addition to
> different environment variables to work. Instead of manually setting
> the environment variables for each application, what would be the best
> way to set PYTHONPATH and other environment variables for a specific
> application? We only run one application at a time, not all of them.
> We are running Python 2.5.2 and Python 2.4.1 on Win2K. Is a bash
> script that sets the environment variables on the application start-up
>  way to go?
>
> Any ideas? I was not aware of site.py until a co-worker bandied it
> about - he says site.py is better than PYTHONPATH.

Don't edit site.py, it is part of the std lib. If you do want to
customize it, add a site-customize.py in your site-packages folder and
put your customizations there.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Kent Johnson
On Tue, Aug 18, 2009 at 9:21 PM, Douglas Philips wrote:

> I think you have five-ish general options:

One more - put required packages and modules into the same directory
as the executable, usually the current directory is on the Python
search path.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python telnet

2009-08-19 Thread Rayon
using python telnet lib to connect to a Nortel switch, and dump some tables. 
My problem is that every now and then the connection is reset by peer . 
Telnet Error : (10054, Connection reset by peer)
I need  to know why, I have it in a loop so it will download after a few tries 
but I need to know why. 
here is the code. 


#main telnet class
import telnetlib
#import telnet lib

class supertelnet: # super tenet class


def __init__(self): # def construct
""

def telNetCall(self, Host, User, Pass, LocalFile):
print "start lens dump"
host  = Host
user  = User
password = Pass
file = LocalFile
telnet  = telnetlib.Telnet(host) # connect to telnet client
#telnet.set_debuglevel(1)
telnet.read_until('Enter User Name', 3) # read session data untill 
match or timeout.
telnet.write(user + '\r') # send username
telnet.write(password + '\r') #send password
# send command to dump len files
# start
print "lens dump in progress"
telnet.write('table ibnlines' + '\r')
telnet.write('format pack' + '\r')
telnet.write('list all' + '\r')
telnet.write('logout' + '\r')
#end of commands
lens =  telnet.read_all() # get session data and store data
print "file write strated"
x = open(file,'wd') # open file
x.write(lens) # write data to file
print "file done"___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] handling a textfile

2009-08-19 Thread Alan Gauld


"Olli Virta"  wrote

I have a textfile (job.txt) that needs modifying. The structure of this 
file

is like this:

AAA1...
BBB1...
CCC1...
AAA2...
BBB2...
CCC2...
etc...
Question is how can I turn this all to a textfile (done.txt) that is 
suppose

to look like this:

AAA1...BBB1...CCC1...
AAA2...BBB2...CCC2...


Lots of ways to do it. The simplest is to read the variables line by line,
so, in pseudo code:

while infile not empty
a = f.readline()
b = f.readline()
c = f.readline()
outfile.write("%s,%s,%s" % (a,b,c) )

If the data is manageable you could read it all into a list then use list
slicing to achieve the same

data = infile.readlines()
for start in range(len(data))[::3]:  # get every third index
outfile.write("%s\t%s\t%s" % tuple(data[start :start+3]) )

I suspect you can do even clever things with itertools using groupby
and such, but I'm no itertools expert - its on my list of things to 
learn... :-)


HTH,


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



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question if my reasoning is right

2009-08-19 Thread Alan Gauld


"Darth Kaboda"  wrote


cb = [[[0, None]] * (n + 1)] * (m + 1)
cb[3][2][0] = 10

This last statement causes the every first element in the list to update.
Is this becuase this method of initializing a list is just a copy


Yes exactly.



To get around this I'm now doing the folowing:
cb = [[[0,None] for x in range(n+1)] for y in range(m+1)]


Yes, that's what list comprehensions are for, to create lists.


Is this an acceptable practice?


Absolutely. It is one of the most common uses for comprehensions.


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



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Setting PYTHONPATH and other env vars dynamically

2009-08-19 Thread Alan Gauld


"Jramak"  wrote


We have developed three custom applications in Python. Each one of
these applications needs a different PYTHONPATH, in addition to
different environment variables to work.


Environment variables should control the users (or oprocess) environment
and as such should really be fairly static, you could cause real problems
if you start changing the users environment dynamically because that might
affect how other applications run that also rely on PYTHONPATH or whatever.

Now, its true that each process gets a copy of the shell environment
so changing it within the process shouldn't affect the external environment
but to me it is still the wrong way to go about it. At the very least it 
means
your environment variables no longer accurately reflect the users 
environment
so you might get surprises if you try and launch a shell process or batch 
job

which picks up the original environment!

In this case I'd much rather change sys.path. That is a Python list and 
much

easier to add items at startup rather than mess with the environment.


the environment variables for each application, what would be the best
way to set PYTHONPATH and other environment variables for a specific
application?


Use config values in an ini file and set global variables in your program
at startup, and for paths use sys.path. (So far as I can tell thats what
Python does with PYTHONPATYH - it loads the values into sys.path
at startup...)


We only run one application at a time, not all of them.
We are running Python 2.5.2 and Python 2.4.1 on Win2K. Is a bash
script that sets the environment variables on the application start-up
way to go?


That is only slightly better since the environment no longer reflects the
users normal environment. It does mean the bash script could launch
multiple programs etc andd they would at lest share a common environment
but in your case I don't think its the best solution.


Any ideas? I was not aware of site.py until a co-worker bandied it
about - he says site.py is better than PYTHONPATH.


They do different things! site.py is about customising Python on that
site - which may be a shared installation - and environment variables
are about describing a users environment, and can be different for
each user. Now, there is an overlap, but Pythonpath is not one of them
since multiple users can share a site! (site.py is probably better
than setting a System wide PYTHONPATH though) But again
site.py applies to every application you should not start modifying
it with application specific startup code - yuck! It could soon turn
into spaghetti and seriously slow down startup of everything.

HTH,


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



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] handling a textfile

2009-08-19 Thread Fidel Sanchez-Bueno

Olli Virta escribió:

Hi!
 
I have a textfile (job.txt) that needs modifying. The structure of 
this file is like this:
 
AAA1...

BBB1...
CCC1...
AAA2...
BBB2...
CCC2...
etc...
 
 
 
Question is how can I turn this all to a textfile (done.txt) that is 
suppose to look like this:
 
AAA1...BBB1...CCC1...

AAA2...BBB2...CCC2...
etc.
 
Thanks! OV
 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  

hi...

i dont think this is the best way of doing it, but you can have an idea 
by reading the code:


some_file="""AAA1...
BBB1...
CCC1...
AAA2...
BBB2...
CCC2..."""

some_tuple=some_file.split()

def change(some_tuple):
   temp=""
   temp2=""
   for x in some_tuple:
   if "1" in x:
   temp+=x
   else:
   temp2+=x
   done= temp +"\n" +temp2
   return done

done_file=change(some_tuple)

is not perfect but you can get the idea..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] handling a textfile

2009-08-19 Thread Olli Virta
Hi!

I have a textfile (job.txt) that needs modifying. The structure of this file
is like this:

AAA1...
BBB1...
CCC1...
AAA2...
BBB2...
CCC2...
etc...



Question is how can I turn this all to a textfile (done.txt) that is suppose
to look like this:

AAA1...BBB1...CCC1...
AAA2...BBB2...CCC2...
etc.

Thanks! OV
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor