473,394 Members | 1,946 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,394 software developers and data experts.

Re: manipulating files within 'for'

Emile van Sebille wrote:
Ben Keshet wrote:
>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'])


At risk of stating the obvious, you _did_ put this in properly as

receptors = ['1AZM', '1ADS']

...right?

Emile
....wrong. I thought I should omit the comma and didn't put it. I guess
that stating the obvious should be the first attempt with beginners like
me. Thanks for thinking about it (it's running perfect now).

BK
>
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?

No error
>what does "exception raised" mean?

Error

--
http://mail.python.org/mailman/listinfo/python-list
Sep 12 '08 #1
4 914
Ben Keshet:
...wrong. I thought I should omit the comma and didn't put it. I guess
that stating the obvious should be the first attempt with beginners like
me. Thanks for thinking about it (it's running perfect now).
In CLisp, Scheme etc, lists such commas aren't necessary, but in
Python if you don't separate strings with a comma they become merged
into a single string:
>>'foo', 'bar'
('foo', 'bar')
>>'foo' 'bar'
'foobar'

Your mistake is caused by Python not following one of its general
rules:

Explicit is better than implicit.

In such case the string concatenation (+) is done implicitly. It's a
little handy feature once in a while (but not for me so far), while it
may cause bugs, so I don't like this little feature of Python and I
may like to see it removed, because it may bite you in similar
situations, where you forgot a comma for mistake:

parts = ["foo", "bar" "baz"]

Bye,
bearophile
Sep 12 '08 #2
be************@lycos.com wrote:
Ben Keshet:
>...wrong. I thought I should omit the comma and didn't put it. I guess
that stating the obvious should be the first attempt with beginners like
me. Thanks for thinking about it (it's running perfect now).

In CLisp, Scheme etc, lists such commas aren't necessary, but in
Python if you don't separate strings with a comma they become merged
into a single string:
>>>'foo', 'bar'
('foo', 'bar')
>>>'foo' 'bar'
'foobar'

Your mistake is caused by Python not following one of its general
rules:

Explicit is better than implicit.

In such case the string concatenation (+) is done implicitly. It's a
little handy feature once in a while (but not for me so far), while it
may cause bugs, so I don't like this little feature of Python and I
may like to see it removed, because it may bite you in similar
situations, where you forgot a comma for mistake:

parts = ["foo", "bar" "baz"]

Bye,
bearophile
It's useful when wrapping a line. For lack of better lorem ipsum:

whatever = some_function("Your mistake is caused by Python not "
"following one of its general rules:\n\n"
"Explicit is better than implicit.")

You can also use backslashes, and probably even + if you want to, but
the implicit concatenation is prettier (IMO, at least ;-).

But you do have a point. I have never thought about the problems it
could cause.

BTW, I could easily be wrong, but I think C behaves the same way as Python.
--
Sep 12 '08 #3
Matt Nordhoff:
It's useful when wrapping a line. For lack of better lorem ipsum:

whatever = some_function("Your mistake is caused by Python not "
"following one of its general rules:\n\n"
"Explicit is better than implicit.")

You can also use backslashes, and probably even + if you want to, but
the implicit concatenation is prettier (IMO, at least ;-).
Adding a + at the end of lines isn't much extra work:

whatever = some_function("Your mistake is caused by Python not " +
"following one of its general rules:\n\n" +
"Explicit is better than implicit.")

Or even:

whatever = "Your mistake is caused by Python not " + \
"following one of its general rules:\n\n" + \
"Explicit is better than implicit."

But you do have a point. I have never thought about the problems it
could cause.
Probably such problems aren't much common, because common bugs are
already prevented by Python designers :-) But I think once I have
written a bug like this:

parts = ["foo", "bar" "baz", "spam"]

Where I meant a list of 4 strings.
BTW, I could easily be wrong, but I think C behaves the same way as Python.
I know, but here changing the behavior respect to C doesn't cause bugs
to C programmers, because in that situation their Python program just
doesn't run. So it's not a Python syntax that looks like a C syntax
that behaves in a different way (this rule is used by the D designer
too: when something behaves differently from C (often to avoid a
common C pitfall), it has a different syntax. Where the D syntax is
the same of C syntax, then the D behavior is generally the same. This
avoids several problems to programmers coming from C/C++).

Bye,
bearophile
Sep 12 '08 #4
Matt Nordhoff:
BTW, I could easily be wrong, but I think C behaves the same way as Python.
C syntax has many traps that are much better out of modern languages
like Python/D/etc.

I think C has that feature because it lacks an operator for string
concatenation, while both Python and D have one (+ and ~. D uses the ~
to avoid any programmer confusion with the mathematical summing
operator), so the situation of Python/D is different.

Bye,
bearophile
Sep 12 '08 #5

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...
1
by: Ben Keshet | last post by:
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.