473,659 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 919
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
5630
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 to the dll during the design time, then when I compile the project and install it, then all the images still inside the dll file. not to be installed into winnet, or system or system32 or any directory, 1) is it possible ? and how ? link or...
10
3278
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 'sizeof(char)'. It seems that I could use bitset<8> to represent a byte in my code --- if you have a better suggestion, I welcome it --- but that still leaves me with the question of how to write those bitsets to an image file as big-endian bytes...
2
2045
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 600M. I've tried every memory conservation trick I know in my conversion program, and a bunch I picked up from reading some of the MSDN C# blogs, but still my program ends up using hundreds and hundreds of megs of ram. It is also taking...
2
2101
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 multiple asmx files, some of them share the same data types (the famous "Order" example). What I want is this final result: - A class file that holds all the proxy classes, but no data types
2
3600
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 and I would like to hide (set the visibility) the div once the user selects a date in the calendar that is part of the user control. The div on the parent page has it's RunAt set to "Server" so I should have no trouble referencing it but I can't...
0
1373
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 C# ut sould be GREAT) to manipulate .ods files? Thanks in advance, Giulio - Italia
0
900
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. Christian
1
1580
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 list of lines. text.find('@') will return the position of the first occurence of '@', or a negative value if not found.
1
1114
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 generates the new file 'pockets.out' correctly, but says:"....py returned exit code 0". However, if I add more values to 'receptor' (say, receptor = ) it gives an error: "Exception raised while running script". Can anyone please advice me? Why is it...
0
740
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
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.