Re: [Tutor] How to test for the existence of a table in a sqlite3 db?

2017-10-14 Thread Flynn, Stephen (L & P - IT)
Yep - oracle for example has hundreds of tables which hold metadata.


for example (this will look terrible due to the length of it but if you assume 
it's 3 lines; a title line, some underlining for each column and the data 
itself):


SQL> select * from all_tables where owner = 'FLYNNS' and table_name = 'QC11483';

OWNER  TABLE_NAME TABLESPACE_NAME   
 CLUSTER_NAME   IOT_NAME   
STATUS PCT_FREE   PCT_USED  INI_TRANS  MAX_TRANS INITIAL_EXTENT NEXT_EXTENT 
MIN_EXTENTS MAX_EXTENTS PCT_INCREASE  FREELISTS FREELIST_GROUPS LOGGING 
BACKED_UP   NUM_ROWS BLOCKS EMPTY_BLOCKS  AVG_SPACE  CHAIN_CNT AVG_ROW_LEN 
AVG_SPACE_FREELIST_BLOCKS NUM_FREELIST_BLOCKS DEGREE INSTANCES  CACHE 
TABLE_LOCK SAMPLE_SIZE LAST_ANALYZED PARTITIONED IOT_TYPE TEMPORARY 
SECONDARY NESTED BUFFER_POOL ROW_MOVEMENT GLOBAL_STATS USER_STATS DURATION  
  SKIP_CORRUPT MONITORING CLUSTER_OWNER  DEPENDENCIES 
COMPRESSION DROPPED
-- -- 
-- -- 
--  -- -- -- 
-- -- --- --- ---  
-- --- --- - -- --  
-- -- --- - --- 
-- -- - -- --- - --- 
 - - -- ---   
-- ---  -- 
--  --- ---
FLYNNS QC11483USERS 
   
VALID10 1255  65536 
  1  2147483645 NO  N   
   61517   10000  0  0 108  
   0   0  1  1 N ENABLED
  61517 30/08/2017 16 NO   N N NO 
DEFAULT DISABLED YES  NO DISABLED 
YES   DISABLED DISABLEDNO

Executed in 0.141 seconds


There's something similar for SQL Server, DB2, ADDABAS, PostGres,, and so forth

S.


From: Tutor  on behalf of 
boB Stepp 
Sent: 14 October 2017 08:17
To: tutor
Subject: Re: [Tutor] How to test for the existence of a table in a sqlite3 db?

On Sat, Oct 14, 2017 at 2:11 AM, boB Stepp  wrote:

> So I get "None" as a result if the target table has not been created
> yet.  But if I *do* create the table I want:
>
> py3: with open('create_sqlite3_db.sql') as f:
> ... sql = f.read()
> ...
> py3: c.executescript(sql)
> 
> py3: tb_exists = "select name from sqlite_master where type='table'
> and name='BloodPressureReadings'"
> py3: tb_ck = c.execute(tb_exists).fetchone()
> py3: print(tb_ck)
> ('BloodPressureReadings',)
>
> So it is looking like I can use this technique to determine if I need
> to create the BloodPressureReadings table or not.  Am I on track here
> or is there a better technique?

It just occurred to me after sending the above, does something like
"sqlite_master" exist for other database programs than sqlite3?  Can I
abstract out "sqlite_master" and replace it with a variable so that I
can handle any kind of database?


--
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


This email is security checked and subject to the disclaimer on web-page: 
http://www.capita.co.uk/email-disclaimer.aspx
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I (idiomatically) determine when I'm looking at the last entry in a list?

2015-10-28 Thread Flynn, Stephen (L & P - IT)
Afternoon,

Python 3.

I'm iterating through a list and I'd like to know when I'm at
the end of the said list, so I can do something different. For example

list_of_things = ['some', 'special', 'things']
for each_entry in list_of_things:
print(each_entry)
if each_entry == list_of_things[-1]: # do something special to
last entry
...etc


Is this the idiomatic way to detect you're at the last entry in a list
as you iterate through it?



For context, I'm working my way through a (csv) file which describes
some database tables. I'm building the Oracle DDL to create that table
as I go. When I find myself building the last column, I want to finish
the definition with a ");" rather than the usual "," which occurs at the
end of all other column definitions...

e.g.
CREATE TABLE wibble
(
Col1CHAR(2),
Col2NUMBER(5,2),
);

Regards,

Steve.


This email is security checked and subject to the disclaimer on web-page: 
http://www.capita.co.uk/email-disclaimer.aspx
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem in packages

2015-07-01 Thread Flynn, Stephen (L P - IT)
 Python version 2.7.10.
 I have problem in installing .whl format packages.
 what version of setuptools is required for .whl format packages.
 I have installed Setuptools version 0.6.0 and upgraded pip to 7.0.3.
 wndows 7 powershell 1.
 I tried installing setuptools 18.0 but it is also in .whl format.
 and installing wheel requires greater than 0.8 versions.
 so how can i install setuptools and wheel to install .whl format
packages.
 please reply as soon as possible.


http://stackoverflow.com/questions/27885397/how-do-i-install-a-python-pa
ckage-with-a-whl-file




This email is security checked and subject to the disclaimer on web-page: 
http://www.capita.co.uk/email-disclaimer.aspx
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Real world use of recursion

2014-09-10 Thread Flynn, Stephen (L P - IT)
 Sorry to bother you all with what you might consider trivia, but
someone
 in my course forum posted this statement:
 
 I have never seen or heard of real uses of recursion except for
proving
 cleverness,
 
 so I thought I would ask you all if that is true.  Is it really not
used
 in real world applications?

Any code which walks a tree is almost certainly going to be using
recursion. This is everything from a chess game analyser, to image
processing software, to your browser when it's rendering a web page and
much more in-between.

There's a very good reason why every single course in coding or any form
of computer science is going to explain it to you at some stage in the
course. It's used a lot, in a lot of places.

S.


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] sys module - what does It is always available mean in the docs?

2014-08-21 Thread Flynn, Stephen (L P - IT)
The documentation (https://docs.python.org/3/library/sys.html) for
Python 3.4.1 says that This module provides access to some variables
used or maintained by the interpreter and to functions that interact
strongly with the interpreter. It is always available.

I interpreted that last sentence as It's built in, so I made the
assumption I didn't need to import it in order to use it.

This is not the case - it still needs to be imported before I can use
anything defined within it.

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64
bit (AMD64)] on win32
Type copyright, credits or license() for more information.
 print(sys.maxsize)
Traceback (most recent call last):
  File pyshell#0, line 1, in module
print(sys.maxsize)
NameError: name 'sys' is not defined
 import sys
 print(sys.maxsize)
9223372036854775807
  

So, what does the documentation mean by explicitly pointing out that sys
is always available? To me, it's misleading but I'm obviously missing a
subtlety.

I've asked this question on /learnpython on reddit recently and the best
explanation is that it's built by the interpreter at runtime, so it
can't fail to import due to a broken installation. Any other offers?


As an addendum, I fired up my local docs via Module Docs and This is
always available *isn't* in the docs page for sys. I'd assumed they
were built from the same sources but apparently not.
-- 
Steve Flynn


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] /tutorial/controlflow.html break statement

2013-12-02 Thread Flynn, Stephen (L P - IT)
 The script studied was :
 
 for n in range(2, 10):
  for x in range(2, n):
  if n % x == 0:
  print(n, 'equals', x, '*', n//x)
  break
  else:
  print(n, 'is a prime number')

The code above is not what you ran below, in idle. Look at the
indentation of the else: line, which completely alters the execution
flow of the code. It should be aligned with a the inner for and you
have it aligned with the inner if.

 Here is the result given in IDLE3 on my Presario CQ61:
 
   for n in range(2,10):
  for x in range(2, n):
  if n % x == 0:
  print(n, '=',x,'*',n//x)
  break
  else:
  # loop fell through without finding a factor
  print(n, 'is a prime number')


Make the change and you'll get the output you were expecting.




This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scheduling Python Execution

2013-04-15 Thread Flynn, Stephen (L P - IT)
 I want to write a twitter bot which runs on a specific time. For an
 idea, I'd like to have this twitter bot tweet every sunrise and
 sunset, everyday. Since everyday the sunrise and the sunset time are
 vary, what are the best way to do it?

Have the bot calculate sunrise and sunset for the following day and
re-schedule itself for those times.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to extract a float from an instancemethod call

2013-04-08 Thread Flynn, Stephen (L P - IT)
Aha - another EdX 6.00 Python course student.

 Traceback (most recent call last):
File /Users/Sydney/Documents/6.00x Files/Problem
 Sets/ProblemSet7/ps7 copy.py, line 303, in module
  testRobotMovement(StandardRobot, RectangularRoom)
File ps7_verify_movement.py, line 12, in testRobotMovement
File /Users/Sydney/Documents/6.00x Files/Problem
 Sets/ProblemSet7/ps7 copy.py, line 285, in updatePositionAndClean
  while self.room.isPositionInRoom(self.position) == False:
File /Users/Sydney/Documents/6.00x Files/Problem
 Sets/ProblemSet7/ps7 copy.py, line 163, in isPositionInRoom
  return self.room[(x,y)] in self.room
 KeyError: (bound method Position.getX of __main__.Position object at
 0x4699490, bound method Position.getY of __main__.Position object
at
 0x4699490)
  
 
 The program text referred to is the following, I give the whole
module,
 which is part of a larger program.
   def isPositionInRoom(self, pos):
  
  Return True if pos is inside the room.
 
  pos: a Position object.
  returns: True if pos is in the room, False otherwise.
  
  x = pos.getX
  y = pos.getY
  return self.room[(x,y)] in self.room


You extract X and Y from the Position object using it's accessor
methods. All you then need to do is check to ensure that both X and Y
are = zero and that both of them, when converted to an into, are less
than room. width and room. height.




This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 3.2: processing text files in binary mode, because I want to remove carriage returns and line feeds...

2012-08-23 Thread Flynn, Stephen (L P - IT)
Python 3.2, as in the subject, although I also have 2.7 on this machine
too.



I have some data which contains text separated with field delimiters
(|~) and a record terminator (||)

12345600990|~5229|~990|~0|~4|~1|~2006-09-08|~13:29:39|~some
text.|~xxx, x|~||
12345600991|~5229|~199|~0|~4|~1|~2009-06-05|~15:25:25|~some
more text|~x, xxa|~||
12345600992|~5119|~998|~8253265|~5|~11|~2011-07-19|~16:55:03
|~Some Split text over
 serveral
 lines
|~Alde, M|~||
12345600993|~5999|~299|~8253265|~5|~11|~2011-07-11|~15:06:53
|~Yet more text: 
 which has been split up with
 carriage returns, line feeds or possibly both, depending upon your
operating system.
|~Imxxx, xxed|~||


I'm trying to reformat this data so that each record terminated with a
|| is on a single line, as in

12345600990|~5229|~990|~0|~4|~1|~2006-09-08|~13:29:39|~some
text.|~xxx, x|~||
12345600991|~5229|~199|~0|~4|~1|~2009-06-05|~15:25:25|~some
more text|~x, xxa|~||
12345600992|~5119|~998|~8253265|~5|~11|~2011-07-19|~16:55:03
|~Some Split text over serveral lines|~Alde, M|~||
12345600993|~5999|~299|~8253265|~5|~11|~2011-07-11|~15:06:53
|~Yet more text:  which has been split up with carriage returns, line
feeds or possibly both, depending upon your operating system.|~Imxxx,
xxed|~||



I've written the following code as a first attempt:

ifile=rC:\Documents and Settings\flynns\Desktop\sample-DCLTBCNTH.txt
ofile=rC:\Documents and Settings\flynns\Desktop\output-DCLTBCNTH.txt

f=open(ifile, mode=rb)
out=open(ofile, mode=w)
line=f.readline()

while (line) :
if '||' in str(line):
print(str(line), file=out)
else:
print(str(line), end='', file=out)
line=f.readline()

if __name__ == '__main__':
pass


The code attempts to read each line of the input file, and if it
contains a ||, print the line to an output file. If it doesn't contain
a || it emits the record without any carriage returns or line feeds
and grabs another line from the input file.

Whilst the logic seems to be working the output file I get out looks
like this:

b'12345600990|~5229|~990|~0|~4|~1|~2006-09-08|~13:29:39|~som
e text.|~xxx, x|~||\r\n'
b'12345600991|~5229|~199|~0|~4|~1|~2009-06-05|~15:25:25|~som
e more text|~x, xxa|~||\r\n'
b'12345600992|~5119|~998|~8253265|~5|~11|~2011-07-19|~16:55:
03|~Some Split test over\r\n'b' serveral\r\n'b' lines\r\n'b'|~Alde,
M|~||\r\n'
b'12345600993|~5999|~299|~8253265|~5|~11|~2011-07-11|~15:06:
53|~Yet more text: \r\n'b' which has been split up with\r\n'b' carriage
returns, line feeds or possibly both, depending upon your operating
system.\r\n'b'|~Imxxx, xxed|~||\r\n'

This makes sense to me as I'm writing the file out in text mode and the
\r and \n in the input stream are being interpreted as simple text.

However, if I try to write the file out in binary mode, I get a
traceback:

Traceback (most recent call last):
  File C:\Documents and
Settings\flynns\workspace\joinlines\joinlines\joinlines.py, line 10, in
module
print(str(line), file=out)
TypeError: 'str' does not support the buffer interface


Is there a method of writing out a binary mode file via print() and
making use of the end keyword?


If there's not, I presume I'll need to remove the \r\n from line in my
else: section and push the amended data out via an out.write(line). How
does one amend bytes in a line object



Steve Flynn



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] converting EBCIDIC to ASCII

2012-07-16 Thread Flynn, Stephen (L P - IT)
I am trying to convert an EBCIDIC file to ASCII, when the records are
fixed length I can convert it fine, I have some files that are coming in
as variable length records, is there a way to convert the file in
Python? I tried using no length but then it just reads in to a fixed
buffer size and I can't seem to break the records properly

Hi Craig,

You might find it easier to pass the records through iconv if
you're on a Linux/Unix box and convert to ISO8859 from IBM037 (or
whatever codepage your ENCDIC files are in). There are versions of this
gnu software for Windows too, if that's your platform - it's trivial to
use. Shout if you need a hand.

Saying that, you'll almost certainly find that the 4 byte RDW
has been stripped from the file when it was sent to you, so you're not
being given any information to determine the length of each variable
length record.

Quick way to check - open the EBCDIC file up in an hex editor (I
use HxD (from http://mh-nexus.de/en/hxd/as it will happily run in EBCDIC
mode). If you can't see 4 bytes at the start of each record, then you're
in trouble as you have no way of determining the record length, without
the copybook for the file on the mainframe.

S.


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] converting EBCIDIC to ASCII

2012-07-16 Thread Flynn, Stephen (L P - IT)
 -Original Message-
 From: tutor-bounces+steve.flynn=capita.co...@python.org [mailto:tutor-
 bounces+steve.flynn=capita.co...@python.org] On Behalf Of Steven
D'Aprano
 Sent: Saturday, July 14, 2012 2:42 AM
 To: tutor@python.org
 Subject: Re: [Tutor] converting EBCIDIC to ASCII
 
 Prinn, Craig wrote:
  I am trying to convert an EBCIDIC file to ASCII, when the records
are
 fixed
  length I can convert it fine, I have some files that are coming in
as
  variable length records, is there a way to convert the file in
Python? I
  tried using no length but then it just reads in to a fixed buffer
size
 and
  I can't seem to break the records properly
 
 
 I'm afraid that I have no idea what you mean here. What are you
actually
 doing? What does tried using no length mean?

The conversion to ASCII from EBCDIC is only going to get Craig so far -
depending on how the sender transferred the files to him, there's a very
good chance that the 4 byte RDW (Record Descriptor Word) has been
stripped off the start of each record.

This 4 byte RDW should indicate that the next N bytes belong to this
record. Without it, you have no way of determining how long the current
record should be and thus where the next RDW should be. This makes
finding the start and end of records tricky to say the least.

I've written to Craig off list with some info as it's not particularly
relevant to Python, other than letting python do the work of iconv.

S.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple text file processing using fileinput module. Grabbing successive lines failure

2012-07-03 Thread Flynn, Stephen (L P - IT)
 On 02/07/12 18:39, David Rock wrote:
 
  Essentially, your problem isn't with using fileinput, it's with how
you
  handle each line that comes in.
 
 The immediate problem is with mis-using fileinput.
 But once you solve that you then have to deal with the
 other issues David raises.
 
 Once more I recommend the csv module...


Thanks gents - seems the CSV module does everything I require so I'll
get tinkering with it.

Steve.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple text file processing using fileinput module.Grabbing successive lines failure

2012-07-03 Thread Flynn, Stephen (L P - IT)
Hi Peter,

 As you already learned the csv module is the best tool to address your
 problem.

Yup - it's almost going to make my little coding exercise trivial. :)

 However, I'd like to show a generic way to get an extra item in a for-
 loop.

[snip]

 Here's a self-contained example:
 
  items = alpha- beta gamma- delta- epsilon zeta.split()
  it = iter(items)
  for item in it:
 ... while item.endswith(-):
 ... item += next(it)
 ... print item
 ...
 alpha-beta
 gamma-delta-epsilon
 zeta

Perfect - that's essentially what I was trying to do, but I doubt it
would have occurred to me to create my own iterator and make use of it.

Thanks for this example too - nice and easy to understand.

Steve.


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Simple text file processing using fileinput module. Grabbing successive lines failure

2012-07-02 Thread Flynn, Stephen (L P - IT)
Tutors,

Whilst having a play around with reading in textfiles and reformatting them I 
tried to write a python 3.2 script to read a CSV file, looking for any records 
which were short (indicating that the data may well contain an embedded CR/LF. 
I've attached a small sample file with a split record at line 3, and my code.

Call the code with

Python pipesmoker.py MyFile.txt ,

(first parameter is the file being read, second parameter is the field 
separator... a comma in this case)

I can read the file in, I can determine that I'm looking for records which have 
13 fields and I can find a record which is too short (line 3).

What I can't do is read the successive line to a short line in order to append 
it onto the end of short line before writing the entire amended line out. I'm 
still thinking about how to persuade the fileinput module to leap over the 
successor line so it doesn't get processed again.

When I run the code as it stands, I get a traceback as I'm obviously not using 
fileinput.FileInput.readline() correctly.

value of file is C:\myfile.txt
value of the delimiter is ,
I'm looking for  13 , in each currentLine...
1,000688  ,ABCD,930020854,34,0,1, ,930020854 ,
  ,0,0,0,0

2,000688  ,ABCD,930020854,99,0,1, ,930020854 ,   
   ,0,0,0,0

short line found at line 3
Traceback (most recent call last):
  File C:\Documents and 
Settings\flynns\workspace\PipeSmoker\src\pipesmoker\pipesmoker.py, line 35, in 
module
nextLine = fileinput.FileInput.readline(args.file)
  File C:\Python32\lib\fileinput.py, line 301, in readline
line = self._buffer[self._bufindex]
AttributeError: 'str' object has no attribute '_buffer'


Can someone explain to me how I am supposed to make use of readline() to grab 
the next line of a text file please? It may be that I should be using some 
other module, but chose fileinput as I was hoping to make the little routine as 
generic as possible; able to spot short lines in tab separated, comma 
separated, pipe separated, ^~~^ separated and anything else which my clients 
feel like sending me.

-- 
Steve Flynn


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
1,000688  ,ABCD,930020854,34,0,1, ,930020854 ,
  ,0,0,0,0
2,000688  ,ABCD,930020854,99,0,1, ,930020854 ,   
   ,0,0,0,0
3,000695  ,ABCD,930610
085,34,0,1, ,930610085 ,  ,0,0,0,0
4,000695  ,ABCD,930610085,99,0,1, ,930610085 ,   
   ,0,0,0,0
5,000696  ,ABCD,930610086,34,0,1, ,930610086 ,   
   ,0,0,0,0
6,000696  ,ABCD,930610086,99,0,1, ,930610086 ,   
   ,0,0,0,0
7,000699  ,ABCD,930610087,34,0,1, ,930610087 ,   
   ,0,0,0,0
8,000699  ,ABCD,930610087,99,0,1, ,930610087 ,   
   ,0,0,0,0
9,000701  ,ABCD,930610088,34,0,1, ,930610088 ,   
   ,0,0,0,0
10,000701  ,ABCD,930610088,99,0,1, ,930610088 ,  
,0,0,0,0


pipesmoker.py
Description: pipesmoker.py
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there space a between #! and /usr/bin/env python ?

2012-05-01 Thread Flynn, Stephen (L P - IT)

 I have seen Python manual, it says #! /usr/bin/env python
 But snippet manager of many text editing programs have #!/usr/bin/env
 python. Python is a strongly typed language, which one is correct?

That's not python code - it's interpreted by the shell (on Linux/Unix)
to determine what to invoke to process the file - in this case the
python interpreter.

Whether there's a space there or not doesn't usually matter to the
shell, and python doesn't care because it's seen as a comment when the
code is compiled.

In short - either is fine.


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 3.2 - difference between out of dir() and help()

2012-03-08 Thread Flynn, Stephen (L P - IT)
Pythonistas,

 

Tinkering around this morning and noticed the following
when I created a tuple and asked for a dir() on it and some help() on
it.

 

 

 x=('rod','jane','freddy')

 dir(x)

['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__',
'__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

 help(x)

Help on tuple object:

 

class tuple(object)

 |  tuple() - empty tuple

[etc... snipped for brevity]

 

 

All pretty standard stuff. I did however notice that the
dir(x) told me about __class__, __reduce__ and __reduce_ex__ where the
help(x) made no mention of them. Why is this difference? I presume the
two commands using different means of getting at and displaying the
methods for an object?

 

Is help() giving me all of the useful methods an object
has which I'm encouraged to make use of, whereas dir gives me a complete
list of everything that object can 'do' including those methods which
aren't really meant for public consumption?

 

 

P.S. Posting from work, so I've configured this mail software to post to
this address in plain text. I'm hoping this email is going to get
converted to plain text when I hit send, as it looks decidedly html/rich
text as I type...

 

Steve Flynn | Technical Architect | Life  Pensions Services | Capita |
The Grange, Bishops Cleeve, GL52 8XX | 01242-670864

Part of Capita plc www.capita.co.uk http://www.capita.co.uk/ 

 

Capita Life  Pensions Services Limited is registered in England No
4359665

Capita Life  Pensions Regulated Services Limited is registered in
England No 2424853

Registered office: 71 Victoria Street, Westminster, London SW1H 0XA

 

Capita Life  Pensions Regulated Services Limited is authorised and
regulated by the Financial Services Authority.

 



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object designer applications - are there any?

2011-08-05 Thread Flynn, Stephen (L P - IT)
I'll certainly give it a look-see - thanks Christian

 

I'm going to end up writing converters anyway, as at some point I'm
going to be given (for example) a COBOL copybook for a file and have to
translate that into an Oracle table version (actually I already have
tools to do this, but if I'm going to be learning python via a project,
I might as well do it properly).

 

S.

 

 



From: Christian Witts [mailto:cwi...@compuscan.co.za] 
Sent: Friday, August 05, 2011 1:10 PM
To: Flynn, Stephen (L  P - IT)
Cc: Tutor List
Subject: Re: [Tutor] Object designer applications - are there any?

 

On 2011/08/05 01:01 PM, Flynn, Stephen (L  P - IT) wrote: 

snip
 
It struck me that if I write a read in Sybase DDL and spit out Oracle
DDL routine and so forth, I'd get a lot of reuse out of it. However,
I've not done much OOP at all and consequently, my object design skills
are somewhat non-existent. Whilst I have a rough idea of what my
properties my table object will have I was looking for something to
help me design it - something which I can say this is a table object,
it has a name and multiple columns. Columns have a type, a width (which
may be further comprised of scale and precision or just an integer
depending on the column type) and a nullable flag.). Oh, and there may
be multiple columns... so maybe a column should be an object too... etc.
 
Anyone know if there are any such kinds of programs out there already
(freeware please - I'll be doing this off my own back so funds are tight
for commercial software). Failing that, does anyone use something for
this kind of thing already, Visio maybe or a spreadsheet. Maybe just
notepad or a post-it?
 
snip
 


You could take a look at SQLAlchemy [1] and possibly the migrate [2]
portion of it for schema management. It supports connectivity for both
Sybase and Oracle as well as being able to generate the DDL [3]

[1] http://www.sqlalchemy.org/docs/
[2]
http://packages.python.org/sqlalchemy-migrate/versioning.html#experiment
al-commands
[3]
http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABL
Eoutputasastring

-- 

Christian Witts
Python Developer

 

Click here
https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==
HJ1tjFMsX3ETe+EpcmOPU7kNPtDbwPBBNdXC8dmstCo9uQ==  to report this email
as spam.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object designer applications - are there any?

2011-08-05 Thread Flynn, Stephen (L P - IT)
  However, I've not done much OOP at all
 
 I'm not sure you need OOP for this. As you say a routine ie a
function
 might be all you need along with some data structures - probably
 dictionaries to define the translations needed.

I suspect you're correct Alan, but as I'm using this an a learning
exercise for the language it seemed too good an opportunity to miss - I
can relate a table to an object in my head quite easily - just need to
know how to do it in Python...


S.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Excited about python

2011-06-10 Thread Flynn, Stephen (L P - IT)
Python manuals from http://www.python.org/doc/

 



From: tutor-bounces+steve.flynn=capita.co...@python.org
[mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of
Kaustubh Pratap chand
Sent: Friday, June 10, 2011 1:41 PM
To: tutor@python.org
Subject: [Tutor] Excited about python

 

Hello,
I just joined this mailing list so that i can boost up my learning of
python.I come from a C background so python looks a little strange to me
but it is easier to learn then any other languages around.Yet,i have not
been able to find any cool books on python for peoples who are already
programmers.The ones which i found which i found were quite boring and
exhaustive.

Can you recommend a book for a person like me which comes with a C
background and the book covers all essential algoithmic methods and
examples?

Thank you.

This email has been scanned for all viruses by the MessageLabs SkyScan
service.


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python scripting using ./

2011-05-24 Thread Flynn, Stephen (L P - IT)
What is your Python executable called? You refer to it as python on
the command line but your #! line in your script refers to the
executable as python3.1. tried it with just python in the #! Line?

Check the output of 'ls -al /usr/local/bin/pytho*'...

S.

-Original Message-
From: tutor-bounces+steve.flynn=capita.co...@python.org
[mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of
Hank Wilkinson
Sent: Tuesday, May 24, 2011 2:10 PM
To: tutor@python.org
Subject: [Tutor] python scripting using ./

I am trying to do script in python using ./
Here is a session showing bad interpreter: No such file or directory
Is this a python question/problem?

Last login: Sat May 21 14:22:49 on ttys000
John-Wilkinsons-iMac:~ wilkinson$ cd
/Users/wilkinson/Documents/py32/p31summerfield
John-Wilkinsons-iMac:p31summerfield wilkinson$ pwd
/Users/wilkinson/Documents/py32/p31summerfield
John-Wilkinsons-iMac:p31summerfield wilkinson$ ls hello.py
hello.py
John-Wilkinsons-iMac:p31summerfield wilkinson$ python hello.py
Hello World!
John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py
John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py
-bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No such
file or directory
John-Wilkinsons-iMac:p31summerfield wilkinson$ echo $PATH
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/
bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py
#!/usr/local/bin/python3.1

print(Hello, World!)
John-Wilkinsons-iMac:p31summerfield wilkinson$ python
Python 3.1.2 (r312:79147, Mar 20 2011, 17:15:01) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type help, copyright, credits or license for more information.
 import sys
 sys.path
['',
'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
1.zip',
'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
.1',
'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
.1/plat-darwin',
'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
.1/lib-dynload',
'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
.1/site-packages']

Thank you.
Hank

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

This email has been scanned for all viruses by the MessageLabs SkyScan
service.

This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python scripting using ./

2011-05-24 Thread Flynn, Stephen (L P - IT)
You missed a * from the end of the ls command but it matters not.

Your python executable is named /usr/local/bin/python3 so if you
change the first line of your script to...

#!/usr/local/bin/python3

...you should get along much better! :)

S.

-Original Message-
From: Hank Wilkinson [mailto:hwilkin...@triad.rr.com] 
Sent: Tuesday, May 24, 2011 2:25 PM
To: Flynn, Stephen (L  P - IT)
Cc: tutor@python.org
Subject: Re: [Tutor] python scripting using ./

John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al
/usr/local/bin/python
ls: /usr/local/bin/python: No such file or directory
John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al
/usr/local/bin/python3
lrwxr-xr-x  1 root  wheel  69 Mar 21 13:45 /usr/local/bin/python3 -
../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3
John-Wilkinsons-iMac:p31summerfield wilkinson$ 

On May 24, 2011, at 9:20 AM, Flynn, Stephen (L  P - IT) wrote:

 What is your Python executable called? You refer to it as python on
 the command line but your #! line in your script refers to the
 executable as python3.1. tried it with just python in the #! Line?
 
 Check the output of 'ls -al /usr/local/bin/pytho*'...
 
 S.
 
 -Original Message-
 From: tutor-bounces+steve.flynn=capita.co...@python.org
 [mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf
Of
 Hank Wilkinson
 Sent: Tuesday, May 24, 2011 2:10 PM
 To: tutor@python.org
 Subject: [Tutor] python scripting using ./
 
 I am trying to do script in python using ./
 Here is a session showing bad interpreter: No such file or directory
 Is this a python question/problem?
 
 Last login: Sat May 21 14:22:49 on ttys000
 John-Wilkinsons-iMac:~ wilkinson$ cd
 /Users/wilkinson/Documents/py32/p31summerfield
 John-Wilkinsons-iMac:p31summerfield wilkinson$ pwd
 /Users/wilkinson/Documents/py32/p31summerfield
 John-Wilkinsons-iMac:p31summerfield wilkinson$ ls hello.py
 hello.py
 John-Wilkinsons-iMac:p31summerfield wilkinson$ python hello.py
 Hello World!
 John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py
 John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py
 -bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No
such
 file or directory
 John-Wilkinsons-iMac:p31summerfield wilkinson$ echo $PATH

/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/
 bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
 John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py
 #!/usr/local/bin/python3.1
 
 print(Hello, World!)
 John-Wilkinsons-iMac:p31summerfield wilkinson$ python
 Python 3.1.2 (r312:79147, Mar 20 2011, 17:15:01) 
 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
 Type help, copyright, credits or license for more information.
 import sys
 sys.path
 ['',

'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
 1.zip',

'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
 .1',

'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
 .1/plat-darwin',

'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
 .1/lib-dynload',

'/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3
 .1/site-packages']
 
 Thank you.
 Hank
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 This email has been scanned for all viruses by the MessageLabs SkyScan
 service.
 
 This email and any attachment to it are confidential.  Unless you are
the intended recipient, you may not use, copy or disclose either the
message or any information contained in the message. If you are not the
intended recipient, you should delete this email and notify the sender
immediately.
 
 Any views or opinions expressed in this email are those of the sender
only, unless otherwise stated.  All copyright in any Capita material in
this email is reserved.
 
 All emails, incoming and outgoing, may be recorded by Capita and
monitored for legitimate business purposes. 
 
 Capita exclude all liability for any loss or damage arising or
resulting from the receipt, use or transmission of this email to the
fullest extent permitted by law.


This email has been scanned for all viruses by the MessageLabs SkyScan
service.

This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use

Re: [Tutor] can I walk or glob a website?

2011-05-18 Thread Flynn, Stephen (L P - IT)
Pardon the crappy quoting - forced to use Exchange. Top posted too...
the shame.

What about curl and libcurl? http://curl.haxx.se/

S.

-Original Message-
From: tutor-bounces+steve.flynn=capita.co...@python.org
[mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of
Alan Gauld
Sent: Wednesday, May 18, 2011 10:18 AM
To: tutor@python.org
Subject: Re: [Tutor] can I walk or glob a website?


Albert-Jan Roskam fo...@yahoo.com wrote 

 How can I walk (as in os.walk) or glob a website? 

I don't think there is a way to do that via the web.
Of course if you have access to the web servers filesystem 
you can use os.walk to do it as for any other filesystem, 
but I don't think its generally possible over http. (And 
indeed it shouldn''t be for very good security reasons!)

OTOH I've been wrong before! :-)




This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Write new line(enter) in txt

2011-03-28 Thread Flynn, Stephen (L P - IT)
Ahhh - my mistake.

You open your file in binary mode - open it in text mode instead and the '\n' 
will be translated to '\n\r' (carriage return and line feed).

I do most of my coding on AIX / Unix where only the Newline is required, so 
that was the first thing I looked for... you're on Windows where an end of line 
is marked via a CR + LF.

S.


From: Susana Iraiis Delgado Rodriguez [mailto:susana.delgad...@utzmg.edu.mx] 
Sent: Monday, March 28, 2011 4:28 PM
To: Flynn, Stephen (L  P - IT)
Cc: tutor@python.org
Subject: Re: [Tutor] Write new line(enter) in txt

Ok Flyyn!
Thank you for answered my question. I think I didn't explain what I need. The 
printing statement is used to print a message to  the Windows console, then the 
other line written in the else statement is:
log.write('No existe el archivo ' +shx+\n)
This is the part I'm struggling with, I don't know how to add the new line to 
the txt
2011/3/28 Flynn, Stephen (L  P - IT) steve.fl...@capita.co.uk
You don't print a newline when you print each line of the file contents...


print 'El archivo ' +shx +' existe'




You need to add a newline:

print 'El archivo ' +shx +' existe' + '\n'





From: tutor-bounces+steve.flynn=capita.co...@python.org 
[mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of Susana 
Iraiis Delgado Rodriguez
Sent: Monday, March 28, 2011 4:12 PM
To: tutor@python.org
Subject: [Tutor] Write new line(enter) in txt

Hello list!!

This is a very simple question!! I want to write some lines in a txt file, but 
my output looks like this:
No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo 
existe el archivo C:\índice_raster.dbf
I need it to look like this:
No existe el archivo C:\índice.dbf
No existe el archivo C:\índice_dwg.dbf
No existe el archivo C:\índice_raster.dbf

The code I wrote is:
log = open ('errors.txt','wb')
shp = 'Error al abrir el archivo' +filepath
log.write(shp+\n)
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
dbf = n[0]+'.dbf'
if os.path.exists(shx):
    print 'El archivo ' +shx +' existe'
    else:
    log.write('No existe el archivo ' +shx+\n)
    if os.path.exists(dbf):
    print 'El archivo ' +dbf +' existe'
    else:
    log.write('No existe el archivo ' +dbf+\n)
log.close()

This email has been scanned for all viruses by the MessageLabs SkyScan service.

This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes.

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.


This email has been scanned for all viruses by the MessageLabs SkyScan service.

This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor