Re: New to Programming - XML Processing

2015-04-01 Thread Mark Lawrence

On 01/04/2015 05:27, Andrew Farrell wrote:

You should follow Rustom's advice before just diving into the blog post
I linked to. Otherwise you risk blindly following things and losing your
bearings when you run into bugs.



Sound advice, but would you please be kind enough to intersperse your 
answers or bottom post as top posting is heavily frowned upon here.


TIA.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Memory Issue using marking property in spotfire

2015-04-01 Thread mohan463
Hi All,

we have developed Iron Python script in spotfire to execute some calculation 
based on the marked rows. The Script holding the memory and not realsing . if 
we marked 1000+ rows its taking MBs of memory and keep on increasing. 

Please help us, is there any way in iron python to release memory. 

Thanks
Mohan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Memory Issue using marking property in spotfire

2015-04-01 Thread Mark Lawrence

On 01/04/2015 11:15, mohan...@gmail.com wrote:

Hi All,

we have developed Iron Python script in spotfire to execute some calculation 
based on the marked rows. The Script holding the memory and not realsing . if 
we marked 1000+ rows its taking MBs of memory and keep on increasing.

Please help us, is there any way in iron python to release memory.

Thanks
Mohan



I'm sorry that I can't help directly, but if you don't get your answer 
here there is an ironpython list at either 
gmane.comp.python.ironpython.user or 
https://mail.python.org/mailman/listinfo/ironpython-users


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging Custom Levels?

2015-04-01 Thread Didymus
On Tuesday, March 31, 2015 at 1:37:29 PM UTC-4, Jean-Michel Pichavant wrote:
> 
> A solution is pretty simple, do not use an intermediate log function pdebug.
> 
> import logging
> PDEBUG_NUM=20
> logging.addLevelName(PDEBUG_NUM, "PDEBUG")
>  
> logger = logging.getLogger('foo')
> logging.basicConfig(level=logging.DEBUG, format='%(message)s %(lineno)d')
> 
> logger.log(PDEBUG_NUM, 'This will work :')
> 
> 
> If you *really* want to go for the hackish way, forget about the inspect 
> module, the following pdebug function should do the trick:
> 
> def pdebug(self, message, *args, **kws):
> if self.isEnabledFor(PDEBUG_NUM):
> self._log(PDEBUG_NUM, message, args, **kws)
> 
> Cheers,
> 
> JM
> 

Very good, thank you!
Tom
 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pycurl.error: (55, 'select/poll returned error')

2015-04-01 Thread Nagy László Zsolt



When calling  curl.perform() on a curl instance I get this:

pycurl.error: (55, 'select/poll returned error')


The same server is happily accepting files over 4GB from other
clients. Those other clients are exactly the same client programs, but
they are running on Windows. Only the one on this FreeBSD box is
throwing the error.

Maybe, you can find out what was the real error reported by
"select/poll" (the "55" above might be the "errno" and in
you OS header files, you may find what it means).

*nix* derivatives have a peculiarity (missing under Windows).
There waiting system calls may prematurely return with
the error "interrupted system call".
Likely, this should give waiting applications a chance to reassess
the state after a signal interrupt and decide for themselves
whether the waiting should be continued. In most contexts,
"interrupted system call" should not be considered an error and the
interrupted call should be restartet. Maybe, "pycurl" misses to do that.

I have figured out that the limit is exactly 2048KB. I'll probably post 
a bug report to pycurl developers.


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Strategy/ Advice for How to Best Attack this Problem?

2015-04-01 Thread Saran A
On Tuesday, March 31, 2015 at 9:19:37 AM UTC-4, Dave Angel wrote:
> On 03/31/2015 07:00 AM, Saran A wrote:
> 
>  > @DaveA: This is a homework assignment.  Is it possible that you 
> could provide me with some snippets or guidance on where to place your 
> suggestions (for your TO DOs 2,3,4,5)?
>  >
> 
> 
> > On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote:
> 
> >>
> >> It's missing a number of your requirements.  But it's a start.
> >>
> >> If it were my file, I'd have a TODO comment at the bottom stating known
> >> changes that are needed.  In it, I'd mention:
> >>
> >> 1) your present code is assuming all filenames come directly from the
> >> commandline.  No searching of a directory.
> >>
> >> 2) your present code does not move any files to success or failure
> >> directories
> >>
> 
> In function validate_files()
> Just after the line
>  print('success with %s on %d reco...
> you could move the file, using shutil.  Likewise after the failure print.
> 
> >> 3) your present code doesn't calculate or write to a text file any
> >> statistics.
> 
> You successfully print to sys.stderr.  So you could print to some other 
> file in the exact same way.
> 
> >>
> >> 4) your present code runs once through the names, and terminates.  It
> >> doesn't "monitor" anything.
> 
> Make a new function, perhaps called main(), with a loop that calls 
> validate_files(), with a sleep after each pass.  Of course, unless you 
> fix TODO#1, that'll keep looking for the same files.  No harm in that if 
> that's the spec, since you moved the earlier versions of the files.
> 
> But if you want to "monitor" the directory, let the directory name be 
> the argument to main, and let main do a dirlist each time through the 
> loop, and pass the corresponding list to validate_files.
> 
> >>
> >> 5) your present code doesn't check for zero-length files
> >>
> 
> In validate_and_process_data(), instead of checking filesize against 
> ftell, check it against zero.
> 
> >> I'd also wonder why you bother checking whether the
> >> os.path.getsize(file) function returns the same value as the os.SEEK_END
> >> and ftell() code does.  Is it that you don't trust the library?  Or that
> >> you have to run on Windows, where the line-ending logic can change the
> >> apparent file size?
> >>
> >> I notice you're not specifying a file mode on the open.  So in Python 3,
> >> your sizes are going to be specified in unicode characters after
> >> decoding.  Is that what the spec says?  It's probably safer to
> >> explicitly specify the mode (and the file encoding if you're in text).
> >>
> >> I see you call strip() before comparing the length.  Could there ever be
> >> leading or trailing whitespace that's significant?  Is that the actual
> >> specification of line size?
> >>
> >> --
> >> DaveA
> >
> >
> 
> > I ask this because I have been searching fruitlessly through for some time 
> > and there are so many permutations that I am bamboozled by which is 
> > considered best practice.
> >
> > Moreover, as to the other comments, those are too specific. The scope of 
> > the assignment is very limited, but I am learning what I need to look out 
> > or ask questions regarding specs - in the future.
> >
> 
> 
> -- 
> DaveA

@DaveA

My most recent commit 
(https://github.com/ahlusar1989/WGProjects/blob/master/P1version2.0withassumptions_mods.py)
 has more annotations and comments for each file. 

I have attempted to address the functional requirements that you brought up:

1) Before, my present code was assuming all filenames come directly from the 
commandline.  No searching of a directory. I think that I have addressed this. 

2) My present code does not move any files to success or failure directories 
(requirements for this assignment1). I am still wondering if and how I should 
use shututil() like you advised me to. I keep receiving a syntax error when 
declaring this below the print statement. 

3) You correctly reminded me that my present code doesn't calculate or write to 
a text file any statistics or errors for the cause of the error. (Should I use 
the copy or copy2 method in order provide metadata? If so, should I wrap it 
into a try and except logic?)

4) Before, my present code runs once through the names, and terminates.  It 
doesn't "monitor" anything. I think I have addressed this with the  main 
function - correct?

5) Before, my present code doesn't check for zero-length files  - I have added 
a comment there in case that is needed) 

I realize appreciate your invaluable feedback. I have grown a lot with this 
assignment!

Sincerely,

Saran
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Programming - XML Processing

2015-04-01 Thread Burak Arslan
On 04/01/15 06:27, catperson wrote:
> I am new to programming, though not new to computers.  I'm looking to
> teach myself Python 3 and am working my way through a tutorial.  At
> the point I'm at in the tutorial I am tasked with parsing out an XML
> file created with a Garmin Forerunner and am just having a terrible
> time getting my head around the concepts.  What I'm looking for is
> some suggested reading that might give me some of the theory of
> operation behind ElementTree and then how to parse out specific
> elements.  Most of what I have been able to find in examples that I
> can understand use very simplistic XML files and this Garmin file is
> many levels of sub-elements and some of those elements have attributes
> assigned, like .

As everybody loves objects, there are many libraries that parse xml
documents to regular python objects (with proper hierarchy). These are
supposed to save you from dealing with ElementTree api directly.

Have a look here:

http://stackoverflow.com/questions/19545067/python-joining-and-writing-xml-etrees-trees-stored-in-a-list

Hth,
Burak


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Addendum to Strategy/ Advice for How to Best Attack this Problem?

2015-04-01 Thread Saran A
On Sunday, March 29, 2015 at 8:33:43 AM UTC-4, Peter Otten wrote:
> Saran Ahluwalia wrote:
> 
> > On Sunday, March 29, 2015 at 7:33:04 AM UTC-4, Saran Ahluwalia wrote:
> >> Below are the function's requirements. I am torn between using the OS
> >> module or some other quick and dirty module. In addition, my ideal
> >> assumption that this could be cross-platform. "Records" refers to
> >> contents in a file. What are some suggestions from the Pythonistas?
> >> 
> >> * Monitors a folder for files that are dropped throughout the day
> >> 
> >> * When a file is dropped in the folder the program should scan the file
> >> 
> >> o IF all the records in the file have the same length
> >> 
> >> o THEN the file should be moved to a "success" folder and a text file
> >> written indicating the total number of records processed
> >> 
> >> o IF the file is empty OR the records are not all of the same length
> >> 
> >> o THEN the file should be moved to a "failure" folder and a text file
> >> written indicating the cause for failure (for example: Empty file or line
> >> 100 was not the same length as the rest).
> > 
> > Below are some functions that I have been playing around with. I am not
> > sure how to create a functional program from each of these constituent
> > parts. I could use decorators or simply pass a function within another
> > function.
> 
> Throwing arbitrary code at a task in the hope that something sticks is not a 
> good approach. You already have given a clear description of the problem, so 
> start with that and try to "pythonize" it. Example:
> 
> def main():
> while True:
> files_to_check = get_files_in_monitored_folder()
> for file in files_to_check:
> if is_good(file):
> move_to_success_folder(file)
> else:
> move_to_failure_folder(file)
> wait_a_minute()
> 
> if __name__ == "__main__":
> main()
> 
> Then write bogus implementations for the building blocks:
> 
> def get_files_in_monitored_folder():
> return ["/foo/bar/ham", "/foo/bar/spam"]
> 
> def is_good(file):
> return file.endswith("/ham")
> 
> def move_to_failure_folder(file):
> print("failure", file)
> 
> def move_to_success_folder(file):
> print("success", file)
> 
> def wait_a_minute():
> raise SystemExit("bye") # we don't want to enter the loop while 
> developing
> 
> Now successively replace the dummy function with functions that do the right 
> thing. Test them individually (preferrably using unit tests) so that when 
> you have completed them all and your program does not work like it should 
> you can be sure that there is a flaw in the main function.
> 
> > [code]
> > import time
> > import fnmatch
> > import os
> > import shutil
> > 
> > 
> > #If you want to write to a file, and if it doesn't exist, do this:
> 
> Hm, are these your personal notes or is it an actual script?
>  
> > if not os.path.exists(filepath):
> > f = open(filepath, 'w')
> > #If you want to read a file, and if it exists, do the following:
> > 
> > try:
> > f = open(filepath)
> > except IOError:
> > print 'I will be moving this to the '
> > 
> > 
> > #Changing a directory to "/home/newdir"
> > os.chdir("/home/newdir")
> 
> Never using os.chdir() is a good habit to get into.
> 
> > def move(src, dest):
> > shutil.move(src, dest)
> > 
> > def fileinfo(file):
> > filename = os.path.basename(file)
> > rootdir = os.path.dirname(file)
> > lastmod = time.ctime(os.path.getmtime(file))
> > creation = time.ctime(os.path.getctime(file))
> > filesize = os.path.getsize(file)
> > 
> > print "%s**\t%s\t%s\t%s\t%s" % (rootdir, filename, lastmod, creation,
> > filesize)
> > 
> > searchdir = r'D:\Your\Directory\Root'
> > matches = []
> > 
> > def search
> 
> Everytime you post code that doesn't even compile you lose some goodwill.
> In a few lines of code meant to demonstrate a problem a typo may be 
> acceptable, but for something that you probably composed in an editor you 
> should take the time to run it and fix at least the syntax errors.
> 
> > for root, dirnames, filenames in os.walk(searchdir):
> > ##  for filename in fnmatch.filter(filenames, '*.c'):
> > for filename in filenames:
> > ##  matches.append(os.path.join(root, filename))
> > ##print matches
> > fileinfo(os.path.join(root, filename))
> > 
> > 
> > def get_files(src_dir):
> > # traverse root directory, and list directories as dirs and files as files
> > for root, dirs, files in os.walk(src_dir):
> > path = root.split('/')
> > for file in files:
> > process(os.path.join(root, file))
> > os.remove(os.path.join(root, file))
> > 
> > def del_dirs(src_dir):
> > for dirpath, _, _ in os.walk(src_dir, topdown=False):  # Listing the
> > files
> > if dirpath == src_dir:
> > break
> > try:
> > os.rmdir(dirpath)
> > except OSError 

ImportError: No module named 'requests.packages.urllib3'

2015-04-01 Thread teqisid
When I am trying to import requests library in python shell, I get this error: 
ImportError: No module named 'requests.packages.urllib3'
I have tried searching online and followed a few probable solutions but yet no 
luck. 
Does anyone know how I can solve this error? 
I am using python 2.7
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named 'requests.packages.urllib3'

2015-04-01 Thread Ian Kelly
On Wed, Apr 1, 2015 at 9:46 AM,   wrote:
> When I am trying to import requests library in python shell, I get this 
> error: ImportError: No module named 'requests.packages.urllib3'
> I have tried searching online and followed a few probable solutions but yet 
> no luck.
> Does anyone know how I can solve this error?
> I am using python 2.7

It sounds like there's something missing from your requests
installation. How did you attempt to install it, and were there any
errors?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named 'requests.packages.urllib3'

2015-04-01 Thread Chris Angelico
On Thu, Apr 2, 2015 at 3:04 AM, Ian Kelly  wrote:
> On Wed, Apr 1, 2015 at 9:46 AM,   wrote:
>> When I am trying to import requests library in python shell, I get this 
>> error: ImportError: No module named 'requests.packages.urllib3'
>> I have tried searching online and followed a few probable solutions but yet 
>> no luck.
>> Does anyone know how I can solve this error?
>> I am using python 2.7
>
> It sounds like there's something missing from your requests
> installation. How did you attempt to install it, and were there any
> errors?

It's also possible that you've shadowed a key module. Copy and paste
the entire traceback, including all the file names, and there might be
a clue somewhere. Or put your code in a file called "1.py", in a
directory on its own, and run that; that name can't accidentally
shadow a normal module name.

(I know this, because I built a WSGI web site that has most of its
code in a file of that name. Importing that took a bit of
hoop-jumping; you can't simply "import 1", because that doesn't make
any sense.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named 'requests.packages.urllib3'

2015-04-01 Thread teqisid
On Wednesday, April 1, 2015 at 12:05:12 PM UTC-4, Ian wrote:
> On Wed, Apr 1, 2015 at 9:46 AM,   wrote:
> > When I am trying to import requests library in python shell, I get this 
> > error: ImportError: No module named 'requests.packages.urllib3'
> > I have tried searching online and followed a few probable solutions but yet 
> > no luck.
> > Does anyone know how I can solve this error?
> > I am using python 2.7
> 
> It sounds like there's something missing from your requests
> installation. How did you attempt to install it, and were there any
> errors?

I installed it using pip. I had to use sudo pip install requests to get the 
module in the site-packages directory. I did not see any error.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named 'requests.packages.urllib3'

2015-04-01 Thread teqisid
On Wednesday, April 1, 2015 at 12:42:39 PM UTC-4, teq...@gmail.com wrote:
> On Wednesday, April 1, 2015 at 12:05:12 PM UTC-4, Ian wrote:
> > On Wed, Apr 1, 2015 at 9:46 AM,   wrote:
> > > When I am trying to import requests library in python shell, I get this 
> > > error: ImportError: No module named 'requests.packages.urllib3'
> > > I have tried searching online and followed a few probable solutions but 
> > > yet no luck.
> > > Does anyone know how I can solve this error?
> > > I am using python 2.7
> > 
> > It sounds like there's something missing from your requests
> > installation. How did you attempt to install it, and were there any
> > errors?
> 
> I installed it using pip. I had to use sudo pip install requests to get the 
> module in the site-packages directory. I did not see any error.

Below is the full stack trace for the error:

Traceback (most recent call last):
  File "/usr/local/bin/behave", line 8, in 
load_entry_point('behave==1.2.4', 'console_scripts', 'behave')()
  File "build/bdist.macosx-10.9-intel/egg/behave/__main__.py", line 111, in main
  File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 659, in run
  File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 665, in 
run_with_paths
  File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 649, in 
load_step_definitions
  File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 306, in 
exec_file
  File 
"/Users/abubakar.siddiq/projects/oms_automation_test/features/steps/callback_ftp.py",
 line 2, in 
import requests
  File "/Library/Python/2.7/site-packages/requests/__init__.py", line 58, in 

from . import utils
  File "/Library/Python/2.7/site-packages/requests/utils.py", line 26, in 

from .compat import parse_http_list as _parse_list_header
  File "/Library/Python/2.7/site-packages/requests/compat.py", line 42, in 

from .packages.urllib3.packages.ordered_dict import OrderedDict
  File "/Library/Python/2.7/site-packages/requests/packages/__init__.py", line 
95, in load_module
raise ImportError("No module named '%s'" % (name,))
ImportError: No module named 'requests.packages.urllib3'

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named 'requests.packages.urllib3'

2015-04-01 Thread teqisid
On Wednesday, April 1, 2015 at 12:44:12 PM UTC-4, teq...@gmail.com wrote:
> On Wednesday, April 1, 2015 at 12:42:39 PM UTC-4, teq...@gmail.com wrote:
> > On Wednesday, April 1, 2015 at 12:05:12 PM UTC-4, Ian wrote:
> > > On Wed, Apr 1, 2015 at 9:46 AM,   wrote:
> > > > When I am trying to import requests library in python shell, I get this 
> > > > error: ImportError: No module named 'requests.packages.urllib3'
> > > > I have tried searching online and followed a few probable solutions but 
> > > > yet no luck.
> > > > Does anyone know how I can solve this error?
> > > > I am using python 2.7
> > > 
> > > It sounds like there's something missing from your requests
> > > installation. How did you attempt to install it, and were there any
> > > errors?
> > 
> > I installed it using pip. I had to use sudo pip install requests to get the 
> > module in the site-packages directory. I did not see any error.
> 
> Below is the full stack trace for the error:
> 
> Traceback (most recent call last):
>   File "/usr/local/bin/behave", line 8, in 
> load_entry_point('behave==1.2.4', 'console_scripts', 'behave')()
>   File "build/bdist.macosx-10.9-intel/egg/behave/__main__.py", line 111, in 
> main
>   File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 659, in run
>   File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 665, in 
> run_with_paths
>   File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 649, in 
> load_step_definitions
>   File "build/bdist.macosx-10.9-intel/egg/behave/runner.py", line 306, in 
> exec_file
>   File 
> "/Users/abubakar.siddiq/projects/oms_automation_test/features/steps/callback_ftp.py",
>  line 2, in 
> import requests
>   File "/Library/Python/2.7/site-packages/requests/__init__.py", line 58, in 
> 
> from . import utils
>   File "/Library/Python/2.7/site-packages/requests/utils.py", line 26, in 
> 
> from .compat import parse_http_list as _parse_list_header
>   File "/Library/Python/2.7/site-packages/requests/compat.py", line 42, in 
> 
> from .packages.urllib3.packages.ordered_dict import OrderedDict
>   File "/Library/Python/2.7/site-packages/requests/packages/__init__.py", 
> line 95, in load_module
> raise ImportError("No module named '%s'" % (name,))
> ImportError: No module named 'requests.packages.urllib3'

Ok, so the import requests works now. But my main goal is to make it work with 
my behave scenarios. It was working before until I did something which I am not 
sure what it is! So, when I try to run any of the behave scenarios, I get the 
listed error. 
-- 
https://mail.python.org/mailman/listinfo/python-list


instance attribute "a" defined outside __init__

2015-04-01 Thread Rio
Hi, When running below code, I get error saying: 

instance attribute "a" defined outside __init__

class Foo:

var = 9

def add(self, a, b):
self.a = a
self.b = b
print a+b

def __init__(self):
print 10

bar = Foo()  # create object

bar.add(4, 7)  # call method by object.method

print bar.var  # access class variable

why the output prints:

10
11
9

why not serially?

9
11
10
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: instance attribute "a" defined outside __init__

2015-04-01 Thread John Gordon
In  Rio 
 writes:

> Hi, When running below code, I get error saying: 

> instance attribute "a" defined outside __init__

That's a warning, not an error.  And it's a warning from pylint,
not from Python itself.

It's trying to suggest better style, that's all.  It's unusual to
define instance variables in functions other __init__.

> class Foo:

> var = 9

> def add(self, a, b):
> self.a = a
> self.b = b
> print a+b

> def __init__(self):
> print 10

> bar = Foo()  # create object

> bar.add(4, 7)  # call method by object.method

> print bar.var  # access class variable

> why the output prints:

> 10
> 11
> 9

10 is printed by Foo.__init__(), when an instance of Foo is created.
11 is printed by calling bar.add(4, 7).
9 is printed by your statement 'print bar.var'.

Your program has those statements in that order, so they are printed
in that order.  Why did you expect a different order?

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to Programming - XML Processing

2015-04-01 Thread catperson
On Tue, 31 Mar 2015 21:17:38 -0700 (PDT), Rustom Mody
 wrote:

>On Wednesday, April 1, 2015 at 8:57:15 AM UTC+5:30, catperson wrote:
>> I am new to programming, though not new to computers.  I'm looking to
>> teach myself Python 3 and am working my way through a tutorial.  At
>> the point I'm at in the tutorial I am tasked with parsing out an XML
>> file created with a Garmin Forerunner and am just having a terrible
>> time getting my head around the concepts.  What I'm looking for is
>> some suggested reading that might give me some of the theory of
>> operation behind ElementTree and then how to parse out specific
>> elements.  Most of what I have been able to find in examples that I
>> can understand use very simplistic XML files and this Garmin file is
>> many levels of sub-elements and some of those elements have attributes
>> assigned, like .
>> 
>> I'm hoping with enough reading I can experiment and work my way
>> through the problem and end up with a hopefully clear understanding of
>> the ElementTree module and Dictionairies.  
>> 
>> Thanks for any suggestions in advance.
>
>Suggestions:
>1. Learn to use the interpreter interactively; ie (at the least)¹ ie
>
>a. Start up python (without a program)
>b. Play around with trivial expressions
>c. Explore introspective features - help(), type() dir()
>
>2. Do you know about triple-quoted strings?
>a. Start small (or trivial) sub-parts of your XML as triple-quoted examples in 
>the 
>interpreter and start throwing them at elementtree
>b. If they dont work trivialize further; if they work add complexity
>---
>¹ At the least because environments like Idle are more conducive to such 
>playing

I thank everyone for their feedback.  I like the above advice and also
Rustom's other comments about learning dictionaries.  I'm thinking in
the back of my mind my issue might be more around the dictionary than
ElementTree at this point.  

 I'll fill in my situation a little based on the queries back to me.

I'm using a book, Python Programming Fundamentals by Kent D. Lee.  

http://knuth.luther.edu/~leekent/IntroToComputing/ 

It looks like he has updated his website since I last looked at it.  I
know there are many tutorials out there, however, I picked this one
and resolved to complete it start to finish.  That means a lot of side
research and reading, which I'm happy to do.  

I've got somewhat of a handle on the basic XML parsing process (my
opinion).  The book uses minidom, but my reading suggests that
ElementTree is a better option, so I thought I'd switch to that and
attempt to duplicate the exercise.

I understand this bit;

import xml.etree.ElementTree as etree
tree = etree.parse('workout.tcx')
root = tree.getroot()

and when I experiment and type root[1][1][0] in a console I can get
the ID field from the xml file with a start time for the workout. That
tells me it parsed properly.  I'm having trouble getting my head
around iterating over the elements, pulling out an activity element
with an attribute of either running or biking, then getting multiple
Trackpoint elements generated by the ForeRunner every 2 minutes, with
an ultimate goal of creating a graph using turtle graphics (later in
the exercise).

I initially thought my trouble was with parsing the xml, but now I'm
thinking my problem is I didn't pay enough attention to iterating over
a dictionary.  I will focus my efforts on Rustom's suggestions so
please don't give me a solution.  Some of my background is automotive
technician, and a statement by one of my instructors has stuck in my
mind over the years.  He said, a friends car won't start, do you take
booster cables or a can of gas with you?  If you understand the theory
of operation of an internal combustion engine, you can solve almost
any problem.

This is a small sample of the xml file.  It's 170239 lines currently.


http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.garmin.com/xmlschemas/ActivityExtension/v2
http://www.garmin.com/xmlschemas/ActivityExtensionv2.xsd
http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2
http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd";>

  

  

  2011-06-06T12:21:04Z
  
3283.170
4821.6821289
2.8058963
398

  125


  167

Active
Manual

  
2011-06-06T12:21:04Z

  34.5225040
  -77.3563351

-0.3433838
0.000

  116

Absent
  

Jim.
-- 
https://mail.python.org/mailman/listinfo/python-list


Gpg python installer

2015-04-01 Thread leonardo davinci
I am using Kleopatra(gpg for win) to verify the 3.4.3 python installer,
Windows x86 MSI

>https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi>
www.python.org 
/ftp/python/3.4.3/
python-3.4.3.msi
>. This file does
not have a email in the digital signature and I am having trouble verifying
the validity of the download.

Any help would be appreciated.
>thanks
>Leo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lockfile hanling

2015-04-01 Thread Sturla Molden
Ian Kelly  wrote:

> As long as there's not *also* some other external process that needs
> to access the file occasionally. :-)

Then there is multiprocessing.Lock :)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strategy/ Advice for How to Best Attack this Problem?

2015-04-01 Thread Dave Angel

On 04/01/2015 09:43 AM, Saran A wrote:

On Tuesday, March 31, 2015 at 9:19:37 AM UTC-4, Dave Angel wrote:

On 03/31/2015 07:00 AM, Saran A wrote:

  > @DaveA: This is a homework assignment.  Is it possible that you
could provide me with some snippets or guidance on where to place your
suggestions (for your TO DOs 2,3,4,5)?
  >



On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote:




It's missing a number of your requirements.  But it's a start.

If it were my file, I'd have a TODO comment at the bottom stating known
changes that are needed.  In it, I'd mention:

1) your present code is assuming all filenames come directly from the
commandline.  No searching of a directory.

2) your present code does not move any files to success or failure
directories



In function validate_files()
Just after the line
  print('success with %s on %d reco...
you could move the file, using shutil.  Likewise after the failure print.


3) your present code doesn't calculate or write to a text file any
statistics.


You successfully print to sys.stderr.  So you could print to some other
file in the exact same way.



4) your present code runs once through the names, and terminates.  It
doesn't "monitor" anything.


Make a new function, perhaps called main(), with a loop that calls
validate_files(), with a sleep after each pass.  Of course, unless you
fix TODO#1, that'll keep looking for the same files.  No harm in that if
that's the spec, since you moved the earlier versions of the files.

But if you want to "monitor" the directory, let the directory name be
the argument to main, and let main do a dirlist each time through the
loop, and pass the corresponding list to validate_files.



5) your present code doesn't check for zero-length files



In validate_and_process_data(), instead of checking filesize against
ftell, check it against zero.


I'd also wonder why you bother checking whether the
os.path.getsize(file) function returns the same value as the os.SEEK_END
and ftell() code does.  Is it that you don't trust the library?  Or that
you have to run on Windows, where the line-ending logic can change the
apparent file size?

I notice you're not specifying a file mode on the open.  So in Python 3,
your sizes are going to be specified in unicode characters after
decoding.  Is that what the spec says?  It's probably safer to
explicitly specify the mode (and the file encoding if you're in text).

I see you call strip() before comparing the length.  Could there ever be
leading or trailing whitespace that's significant?  Is that the actual
specification of line size?

--
DaveA






I ask this because I have been searching fruitlessly through for some time and 
there are so many permutations that I am bamboozled by which is considered best 
practice.

Moreover, as to the other comments, those are too specific. The scope of the 
assignment is very limited, but I am learning what I need to look out or ask 
questions regarding specs - in the future.




--
DaveA


@DaveA

My most recent commit 
(https://github.com/ahlusar1989/WGProjects/blob/master/P1version2.0withassumptions_mods.py)
 has more annotations and comments for each file.


Perhaps you don't realize how github works.  The whole point is it 
preserves the history of your code, and you use the same filename for 
each revision.


Or possibly it's I that doesn't understand it.  I use git, but haven't 
actually used github for my own code.




I have attempted to address the functional requirements that you brought up:

1) Before, my present code was assuming all filenames come directly from the 
commandline.  No searching of a directory. I think that I have addressed this.



Have you even tried to run the code?  It quits immediately with an 
exception since your call to main() doesn't pass any arguments, and main 
requires one.


> def main(dirslist):
> while True:
> for file in dirslist:
>return validate_files(file)
>time.sleep(5)

In addition, you aren't actually doing anything to find what the files 
in the directory are.  I tried to refer to dirlist, as a hint.  A 
stronger hint:  look up  os.listdir()


And that list of files has to change each time through the while loop, 
that's the whole meaning of scanning.  You don't just grab the names 
once, you look to see what's there.


The next thing is that you're using a variable called 'file', while 
that's a built-in type in Python.  So you really want to use a different 
name.


Next, you have a loop through the magical dirslist to get individual 
filenames, but then you call the validate_files() function with a single 
file, but that function is expecting a list of filenames.  One or the 
other has to change.


Next, you return from main after validating the first file, so no others 
will get processed.



2) My present code does not move any files to success or failure directories 
(requirements for this assignment1). I am still wondering if and ho

Re: New to Programming - XML Processing

2015-04-01 Thread sohcahtoa82
On Wednesday, April 1, 2015 at 3:34:15 PM UTC-7, catperson wrote:
> On Tue, 31 Mar 2015 21:17:38 -0700 (PDT), Rustom Mody
>  wrote:
> 
> >On Wednesday, April 1, 2015 at 8:57:15 AM UTC+5:30, catperson wrote:
> >> I am new to programming, though not new to computers.  I'm looking to
> >> teach myself Python 3 and am working my way through a tutorial.  At
> >> the point I'm at in the tutorial I am tasked with parsing out an XML
> >> file created with a Garmin Forerunner and am just having a terrible
> >> time getting my head around the concepts.  What I'm looking for is
> >> some suggested reading that might give me some of the theory of
> >> operation behind ElementTree and then how to parse out specific
> >> elements.  Most of what I have been able to find in examples that I
> >> can understand use very simplistic XML files and this Garmin file is
> >> many levels of sub-elements and some of those elements have attributes
> >> assigned, like .
> >> 
> >> I'm hoping with enough reading I can experiment and work my way
> >> through the problem and end up with a hopefully clear understanding of
> >> the ElementTree module and Dictionairies.  
> >> 
> >> Thanks for any suggestions in advance.
> >
> >Suggestions:
> >1. Learn to use the interpreter interactively; ie (at the least)š ie
> >
> >a. Start up python (without a program)
> >b. Play around with trivial expressions
> >c. Explore introspective features - help(), type() dir()
> >
> >2. Do you know about triple-quoted strings?
> >a. Start small (or trivial) sub-parts of your XML as triple-quoted examples 
> >in the 
> >interpreter and start throwing them at elementtree
> >b. If they dont work trivialize further; if they work add complexity
> >---
> >š At the least because environments like Idle are more conducive to such 
> >playing
> 
> I thank everyone for their feedback.  I like the above advice and also
> Rustom's other comments about learning dictionaries.  I'm thinking in
> the back of my mind my issue might be more around the dictionary than
> ElementTree at this point.  
> 
>  I'll fill in my situation a little based on the queries back to me.
> 
> I'm using a book, Python Programming Fundamentals by Kent D. Lee.  
> 
> http://knuth.luther.edu/~leekent/IntroToComputing/ 
> 
> It looks like he has updated his website since I last looked at it.  I
> know there are many tutorials out there, however, I picked this one
> and resolved to complete it start to finish.  That means a lot of side
> research and reading, which I'm happy to do.  
> 
> I've got somewhat of a handle on the basic XML parsing process (my
> opinion).  The book uses minidom, but my reading suggests that
> ElementTree is a better option, so I thought I'd switch to that and
> attempt to duplicate the exercise.
> 
> I understand this bit;
> 
> import xml.etree.ElementTree as etree
> tree = etree.parse('workout.tcx')
> root = tree.getroot()
> 

>   34.5225040
>   -77.3563351

> Jim.

This is on the coast of North Carolina, for anyone curious, just south of 
Snead's Ferry.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Gpg python installer

2015-04-01 Thread E Smitty
On Wednesday, April 1, 2015 at 4:26:40 PM UTC-7, leonardo davinci wrote:
> I am using Kleopatra(gpg for win) to verify the 3.4.3 python installer, 
> Windows x86 MSI
> 
> >. This file does 
> >not have a email in the digital signaure and I am having trouble verifying 
> >the validity of the download.
> 
> Any help would be appreciated.
> 
> >thanks
> 
> >Leo

Could you tell us what steps you have taken?
-- 
https://mail.python.org/mailman/listinfo/python-list