473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

manipulating files within 'for'

Hi Pythoneers,

I have a question about a code I wrote with the help of someone. The
code below copy a few lines from different files into one file. It works
fine as it is given here and generates the new file 'pockets.out'
correctly, but says:"....py returned exit code 0". However, if I add
more values to 'receptor' (say, receptor = ['1AZM' '1ADS']) it gives an
error: "Exception raised while running script".

Can anyone please advice me? Why is it giving an error on multiple x but
runs well with one (I made sure that all files and folders exist, etc.).
What does exit code 0 mean? what does "exception raised" mean?

Thanks a lot,
BK

CODE:

|receptors = ['1AZM']
for x in receptors:
print x
# open out_file for appending for each 'x' in receptors, close at
same level
out_file =
open('c:/Linux/Dock_method_validation/%s/validation/pockets.out' %(x),'a')
for i in range(10):
for r in (7, 9, 11, 13, 15, 17):
f = open('%s/validation/ligand_ran_line_%s_%s.mol2'
%(x,i,r), 'r')
out_file.write('%s ' %i)
out_file.write('%s ' %r)
# assume 'PRIMARY' should be found first
# set flag for string 'PRIMARY'
primary = False
# iterate on file object, empty files will be skipped
for line in f:
if 'PRIMARY' in line:
primary = True
out_file.write(line.strip()) # write line to out_file
out_file.write(' ') # add a space
# write all line after 'PRIMARY' was found until
'TRIPOS' is found
elif 'TRIPOS' not in line and primary:
out_file.write(line.strip())
out_file.write(' ') # add a space
elif 'TRIPOS' in line and primary:
break # stop when
'TRIPOS' is found
print
out_file.write('\n') # move to a new line
f.close() # close file. for loop moves to next 'r'
value, and then to next 'i'
out_file.close() # close out_file|
Sep 12 '08 #1
1 1098
On Sep 12, 6:11*pm, Ben Keshet <kesh...@umbc.eduwrote:
Hi Pythoneers,

I have a question about a code I wrote with the help of someone. The
code below copy a few lines from different files into one file. It works
fine as it is given here and generates the new file 'pockets.out'
correctly, but says:"....py returned exit code 0". However, if I add
more values to 'receptor' (say, receptor = ['1AZM' '1ADS']) it gives an
error: "Exception raised while running script".
You should post the full error if you want some help which is more
than speculation
>
Can anyone please advice me? Why is it giving an error on multiple x but
runs well with one (I made sure that all files and folders exist, etc.).
What does exit code 0 mean? what does "exception raised" mean?
I guess you are on Windows, but how do you run your script? Do you do
it from the command line or do you use some IDE?

--
Arnaud

Sep 12 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: MAK | last post by:
Hello everyone, I know how to add images and icons etc to dll file. What I would like to know is there is a way to add those icons on the forms during the run time from the dll or to reference it ...
10
by: Kristian Nybo | last post by:
Hi, I'm writing a simple image file exporter as part of a school project. To implement my image format of choice I need to work with big-endian bytes, where 'byte' of course means '8 bits', not...
2
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and...
2
by: Ido Flatow | last post by:
Hi all, I've been exploring the way I can manipulate WSDL.exe using SchemaImporterExtension in order to create a proxy to my liking. My situation is as follows - I have a web site that has...
2
by: David Hearn | last post by:
I have a user control that is embedded into a <DIVtag in my aspx page. The div tags visibility is set to true from the page when the user clicks on an image. There is a user control within the div...
0
by: Giulio Petrucci | last post by:
Hi there, I need to accomplish this (trivial) task: I have some .csv files and I have to place them into differente sheets of a .ods file. As far as you know, is there any .NET library (and in...
0
by: Christian Heimes | last post by:
Wilbert Berendsen schrieb: It's really tricky . The class object doesn't exists yet. It's created after all functions are parsed and created. You have can walk up the stack frames but it's ugly....
1
by: =?utf-8?q?C=C3=A9dric_Lucantis?= | last post by:
Le Wednesday 02 July 2008 01:16:30 Ben Keshet, vous avez écrit : If the file you're reading is not too big, you can use file.readlines() which read all the files and returns its content as a...
0
by: Emile van Sebille | last post by:
Ben Keshet wrote: At risk of stating the obvious, you _did_ put this in properly as receptors = ....right? Emile
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.