See Subject. It's a simple txt file, each line is a Python stmt, but I need
up to four digits added to each line with a space between the number field
and the text. Perhaps someone has already done this or there's a source on
the web for it. I'm not yet into files with Python. A sudden need has burst
upon me. I'm using Win XP.
--
Wayne Watson (Nevada City, CA)
Web Page: <speckledwithSt ars.net> 18 2438
On Feb 14, 8:54 am, "W. Watson" <wolf_tra...@in valid.comwrote:
See Subject. It's a simple txt file, each line is a Python stmt, but I need
up to four digits added to each line with a space between the number field
and the text. Perhaps someone has already done this or there's a source on
the web for it. I'm not yet into files with Python. A sudden need has burst
upon me. I'm using Win XP.
--
Wayne Watson (Nevada City, CA)
Web Page: <speckledwithSt ars.net>
enumerate through the file which will yield you a counter (starting @
zero so just add 1) and use the string function .zfill() to pad it out
for you.
eg.
for (line_cnt, each_line) in enumerate(input _file):
output_file.wri te(print ('%s '%(line_cnt+1)) .zfill(5) + each_line)
output_file.clo se()
input_file.clos e()
On Feb 14, 6:13 pm, Chris <cwi...@gmail.c omwrote:
On Feb 14, 8:54 am, "W. Watson" <wolf_tra...@in valid.comwrote:
See Subject. It's a simple txt file, each line is a Python stmt, but I need
up to four digits added to each line with a space between the number field
and the text. Perhaps someone has already done this or there's a source on
the web for it. I'm not yet into files with Python. A sudden need has burst
upon me. I'm using Win XP.
--
Wayne Watson (Nevada City, CA)
Web Page: <speckledwithSt ars.net>
enumerate through the file which will yield you a counter (starting @
zero so just add 1) and use the string function .zfill() to pad it out
for you.
eg.
for (line_cnt, each_line) in enumerate(input _file):
output_file.wri te(print ('%s '%(line_cnt+1)) .zfill(5) + each_line)
(1) What's that "print" doing in there?
(2) zfill(5)? The OP asked for "up to 4 digits", not 5.
(2) As an alternative to str.zfill, consider using formatting:
output_file.wri te('%04d %s' % (line_cnt+1, each_line))
And what does "up to 4" mean? What does the OP want the 10000th line
to look like?
On Feb 14, 1:29 pm, John Machin <sjmac...@lexic on.netwrote:
On Feb 14, 6:13 pm, Chris <cwi...@gmail.c omwrote:
On Feb 14, 8:54 am, "W. Watson" <wolf_tra...@in valid.comwrote:
See Subject. It's a simple txt file, each line is a Python stmt, but I need
up to four digits added to each line with a space between the number field
and the text. Perhaps someone has already done this or there's a source on
the web for it. I'm not yet into files with Python. A sudden need has burst
upon me. I'm using Win XP.
--
Wayne Watson (Nevada City, CA)
Web Page: <speckledwithSt ars.net>
enumerate through the file which will yield you a counter (starting @
zero so just add 1) and use the string function .zfill() to pad it out
for you.
eg.
for (line_cnt, each_line) in enumerate(input _file):
output_file.wri te(print ('%s '%(line_cnt+1)) .zfill(5) + each_line)
(1) What's that "print" doing in there?
(2) zfill(5)? The OP asked for "up to 4 digits", not 5.
(2) As an alternative to str.zfill, consider using formatting:
output_file.wri te('%04d %s' % (line_cnt+1, each_line))
And what does "up to 4" mean? What does the OP want the 10000th line
to look like?
print was a typo
take a look at the string that is built before the zfill fires, it has
a trailing space so it is correct. ;)
Thanks. I found this to work:
input_file=open ('junkin.txt',' r')
output_file=ope n('junkout.txt' ,'w')
for (line_cnt, each_line) in enumerate(input _file):
output_file.wri te('%4d '%(line_cnt+1)+ each_line)
output_file.clo se()
input_file.clos e()
I removed the print, but ran into trouble with zfill. I thought this might
be more difficult judging by a long ago experience with Java.
Chris wrote:
On Feb 14, 1:29 pm, John Machin <sjmac...@lexic on.netwrote:
>On Feb 14, 6:13 pm, Chris <cwi...@gmail.c omwrote:
>>On Feb 14, 8:54 am, "W. Watson" <wolf_tra...@in valid.comwrote: See Subject. It's a simple txt file, each line is a Python stmt, but I need up to four digits added to each line with a space between the number field and the text. Perhaps someone has already done this or there's a source on the web for it. I'm not yet into files with Python. A sudden need has burst upon me. I'm using Win XP. -- Wayne Watson (Nevada City, CA) Web Page: <speckledwithSt ars.net> enumerate through the file which will yield you a counter (starting @ zero so just add 1) and use the string function .zfill() to pad it out for you. eg. for (line_cnt, each_line) in enumerate(input _file): output_file.wri te(print ('%s '%(line_cnt+1)) .zfill(5) + each_line)
(1) What's that "print" doing in there? (2) zfill(5)? The OP asked for "up to 4 digits", not 5. (2) As an alternative to str.zfill, consider using formatting:
output_file.wr ite('%04d %s' % (line_cnt+1, each_line))
And what does "up to 4" mean? What does the OP want the 10000th line to look like?
print was a typo
take a look at the string that is built before the zfill fires, it has
a trailing space so it is correct. ;)
--
Wayne Watson (Nevada City, CA)
Web Page: <speckledwithSt ars.net>
On Feb 14, 8:50 am, "W. Watson" <wolf_tra...@in valid.comwrote:
(snip)
I thought this might be more difficult judging by a long ago experience with Java.
(snip)
+1 QOTW
En Thu, 14 Feb 2008 04:54:56 -0200, W. Watson <wo*********@in valid.com>
escribió:
See Subject. It's a simple txt file, each line is a Python stmt, but I
need
up to four digits added to each line with a space between the number
field
and the text. Perhaps someone has already done this or there's a source
on
the web for it. I'm not yet into files with Python. A sudden need has
burst
upon me. I'm using Win XP.
This command should suffice - but you must first find a working CP/M
system to use it:
C>PIP [N] NEW.PY=OLD.PY
(Sorry - just a a nostalgic flash!)
--
Gabriel Genellina
Good grief! You go a long way back. Want to try for an IBM 650 with a drum
memory?
Gabriel Genellina wrote:
En Thu, 14 Feb 2008 04:54:56 -0200, W. Watson <wo*********@in valid.com>
escribió:
>See Subject. It's a simple txt file, each line is a Python stmt, but I need up to four digits added to each line with a space between the number field and the text. Perhaps someone has already done this or there's a source on the web for it. I'm not yet into files with Python. A sudden need has burst upon me. I'm using Win XP.
This command should suffice - but you must first find a working CP/M
system to use it:
C>PIP [N] NEW.PY=OLD.PY
(Sorry - just a a nostalgic flash!)
--
Wayne Watson (Nevada City, CA)
Web Page: <speckledwithSt ars.net>
Gabriel Genellina wrote:
En Thu, 14 Feb 2008 04:54:56 -0200, W. Watson <wo*********@in valid.com>
escribió:
>See Subject. It's a simple txt file, each line is a Python stmt, but I need up to four digits added to each line with a space between the number field and the text. Perhaps someone has already done this or there's a source on the web for it. I'm not yet into files with Python. A sudden need has burst upon me. I'm using Win XP.
This command should suffice - but you must first find a working CP/M
system to use it:
C>PIP [N] NEW.PY=OLD.PY
(Sorry - just a a nostalgic flash!)
Wow! You remembered this. Good old PIP!
Jaap
Gabriel Genellina wrote:
>En Thu, 14 Feb 2008 04:54:56 -0200, W. Watson <wo*********@in valid.com> escribió:
>>See Subject. It's a simple txt file, each line is a Python stmt, but I need up to four digits added to each line with a space between the number field and the text.
>This command should suffice - but you must first find a working CP/M system to use it:
C>PIP [N] NEW.PY=OLD.PY
(Sorry - just a a nostalgic flash!)
En Thu, 14 Feb 2008 19:47:16 -0200, Jaap Spies <j.*****@hccnet .nl>
escribió:
Wow! You remembered this. Good old PIP!
So powerful... It was one of the first things I learned, perhaps that's
why I still remember it.
En Thu, 14 Feb 2008 18:53:16 -0200, W. Watson <wo*********@in valid.com>
escribió:
Good grief! You go a long way back. Want to try for an IBM 650 with a
drum
memory?
I can't go soooo long back in time :) but I remember having used a
Winchester removable hard drive, maybe 30MB capacity, that made a terrible
noise and had to be powered on a few minutes earlier than the main unit
because it had to "speed up".
--
Gabriel Genellina This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro capabilities, unfortunately. I'd like to know if it may
be possible to add a powerful macro system to Python, while
keeping its amazing syntax, and if it could be possible to
add Pythonistic syntax to Lisp or Scheme, while keeping all
of the...
|
by: Stephen C. Waterbury |
last post by:
This seems like it ought to work, according to the
description of reduce(), but it doesn't. Is this
a bug, or am I missing something?
Python 2.3.2 (#1, Oct 20 2003, 01:04:35)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d1 = {'a':1}
>>> d2 = {'b':2}
>>> d3 = {'c':3}
|
by: Ville Vainio |
last post by:
I don't know if you have seen this before, but here goes:
http://text.userlinux.com/white_paper.html
There is a jab at Python, though, mentioning that Ruby is more
"refined".
--
Ville Vainio http://www.students.tut.fi/~vainio24
|
by: Olivier Scalbert |
last post by:
Hello ,
What is the python way of doing this :
perl -pi -e 's/string1/string2/' file
?
Thanks
Olivier
|
by: Carlos Ribeiro |
last post by:
Oh well. A mailing list is not the most appropriate place for rants (a
blog is better), but it's still better than keeping it for myself.
I'm frustrated. My search for a good IDE to support my activities --
doing development for Python in the Windows environment -- are not
being succesful as I had originally dreamt. I have big constraints on
what can I do now; money is not an option, and my current machine is
still useful but it's below...
| |
by: Paul Kooistra |
last post by:
I need a tool to browse text files with a size of 10-20 Mb. These
files have a fixed record length of 800 bytes (CR/LF), and containt
records used to create printed pages by an external company.
Each line (record) contains an 2-character identifier, like 'A0' or
'C1'. The identifier identifies the record format for the line,
thereby allowing different record formats to be used in a textfile.
For example:
An A0 record may consist of:
|
by: Lad |
last post by:
Is anyone capable of providing Python advantages over PHP if there are
any?
Cheers,
L.
|
by: Omar |
last post by:
I'd love the perfect editor that would be:
a) free
b) enable me to drag and drop code snippets from a sort of browser into
the code
c) can run programs right from within
d) can edit
|
by: Banfa |
last post by:
Posted by Banfa
The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how we set about doing that.
Every program starts with a specification, this may be a several hundred page document from your latest client or one small paragraph from your professor and pretty much anything in-between.
The specification is very...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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...
|
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();...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |