Re: [Tutor] Border width of Canvas widget in tkinter

2012-09-19 Thread Peter Otten
Alok Joshi wrote:

> I am using Python 3.x
> 
> I am unable to remove the border in a Canvas widget with bd=0 or
> borderwidth=0. Can someone please explain how one can do this?
> 
> I give below my program
> 
> class Avatar(Frame):
> def
> 
__init__(self,parent=None,width=100,height=100,ovalness=1,bgFrameColor='Blue',bgCanvasColor='Black'):
> Frame.__init__(self,parent,width=width,height=height,bg=bgFrameColor)
> self.grid() #self.grid_propagate(0)
> 
> self.width=width
> self.height=height
> self.ovalness=ovalness
> self.bgFrameColor=bgFrameColor
> self.bgCanvasColor=bgCanvasColor
> 
> 
self.canvas1=Canvas(self,width=width/2,height=height/2,bg=bgCanvasColor,borderwidth=0)
> self.canvas1.grid(row=0,column=0,ipadx=0,ipady=0,padx=0,pady=0)
> self.canvas1.grid_propagate(0)
> 
self.canvas2=Canvas(self,width=width/2,height=height/2,bg=bgCanvasColor,borderwidth=0)
> self.canvas2.grid(row=1,column=1,ipadx=0,ipady=0,padx=0,pady=0)
> self.canvas2.grid_propagate(0)
> 
> self.draw()
> def draw(self):
> pass
> 
> if __name__=='__main__':
> root=Tk()
> x=Avatar(parent=root)
> x.mainloop()
> 
> when I run this program I can see a gray border on the two canvas objects.

After some experimentation I could identify "highlightthickness" as the 
culprit:

import Tkinter as tk
root = tk.Tk()
frame = tk.Frame(root, bg="yellow")
frame.pack(fill="both", expand=True)
for i in range(2):
canvas = tk.Canvas(frame, width=100, height=100, highlightthickness=0, 
bg="black")
canvas.grid(row=i, column=i)
root.mainloop()

To get there I usually throw something like 

print list(canvas).config())

and look for promising candidates.

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Peter Otten
Gregory Lund wrote:

> I teach at a college and I'm trying to use Python (2.6 because I'm
> running my tool in ArcGIS) to unzip a .zip file that contains one
> folder full of student folders, each with 1 or more submissions
> (zipfiles) that represent student submissions to weekly lab
> assignments.

Your lack of response in the previous thread

http://mail.python.org/pipermail/tutor/2012-August/090742.html

is not a big motivation to answer this one.
 
> It all starts with an originalzip.zip (for example) that has a single
> folder (originalfolder)
> Within the 'originalfolder' folder there are anywhere from 1 - 40
> folders (that are not zipped). (these are the students userid folders)
> Within each of the (1-40) student userid folders is anywhere from 1-10
> zipfiles and perhaps a .pdf or .docx (if for example they submitted
> more than one revision of the assignment, there are more than 1)
> 
> Folder Structure
> 
> originalzip.zip
> --originalfolder
>   --folder1 (w/ two zip folders)
> --internalzip1_a.zip
> --internalfolder1_a
>   --files
>   --folders
> --internalzip1_b.zip
> --internalfolder1_b
>   --files
>   --folders
>   --folder2 (w/1 zip folder)
> --internalzip2.zip
> --internalfolder2
>   --files
>   --folders
>   --etc
> 
> My goal is to:
> a) Unzip the 'originalzip.zip'
> b) go to the 'originalfolder' (the unzipped version of the
> originalzip.zip) c) go into the first folder (folder1) in the original
> folder and unzip any and all zipfiles within it
> d) go to the second folder (folder2) in the original folder and unzip
> any and all zipfiles within it
> e) continue until all folders within originalfolders have been checked
> for internalzips
> 
> 
> ### Note, I am a beginner both with this tutor environment and in python.
> I apologize in advance if my code below is 'not up to par' but I am
> trying to keep it simple in nature and use ample comments to keep
> track of what I am doing. I also don't know if I should post sample
> data (zipfile of a folder of folders with zipfiles), and if so, where?
> 
> I have some code that works to extract the 'originalzip.zip', to an
> 'originalfolder' but it won't go to the folders (folder1, folder2,
> etc.) to unzip the zipfiles within them.
> It gets hung up on access to the first student folder and won't unzip it.

Hm, I would have expeced an exception. Perhaps you should omit the ArcGIS 
integration until everything else works.

> I think it's a simple fix, but I've been messing with it for quite a
> while and can't figure it out.
> 
> Code below:
> 
> #1 Required imports.

Excessive comments impair readability. Comments stating the obvious are 
particularly bad.

> import os, os.path, zipfile, arcpy
> 
> #2 I'm Utilizing 'GetParameterAsText' so that this code can be run as
> a tool in ArcGIS
> 
> #2.1 in_zip is a variable for "What zipfile (LAB) do you want to extract?"
> in_Zip = arcpy.GetParameterAsText(0)
> cZ = in_Zip

Why two names for one value?
 
> #2.2 outDir is a variable for "What is your output Directory?"
> outDir = os.getcwd()
> 
> #3 Extracting the initial zipfolder:
> #3.1 Opening the original zipfile
> z = zipfile.ZipFile(cZ)
> 
> #4 Extracting the cZ (original zipfile)into the output directory.
> z.extractall(outDir)
> 
> #5 Getting a list of contents of the original zipfile
> zipContents = z.namelist()
> 
> #6 Unzipping the Inner Zips:
> 
> #6.1 Looping through the items that were in the original zipfile, and
> now in a folder...
> #   ...For each item in the zipContents
> for item in zipContents:

You make no attempt to filter out the contents that are not zipfiles. That 
will cause an exception further down where you try to unzip.
 
> #6.2 Get the location (note the location is the 'outDir' plus what
> namelist() gave me)
> #(have never used 'os.sep', had to look it up, when someone suggested
> #it)
> itemLoc = outDir + os.sep + item

The standard way (which is also more robust) is to use os.path.join():

  itemLoc = os.path.join(outDir, item)
 
> #6.3 Opens the first (2nd, 3rd, etc files) of the internal zip file
> #(*.zip)
> z = zipfile.ZipFile(itemLoc)
> 
> #6.4 Extract all files in *.zip in the same folder as the zipfile
> z.extractall(os.path.split(itemLoc)[0])

The zip files's contents will probably end up in the same folder as the 
zipfile. Is that what you want?
> 
> #6.5 determining the list of items in each students' folder
> student_lab = z.namelist()

Unused variable alert.

> 
> #7 THE END.
> 
> Thank you for any and all suggestions/ fixes, constructive criticism
> and assistance with my beginner code!

Have you considered the simpler code I gave in 

http://mail.python.org/pipermail/tutor/2012-August/090743.html

before prodding on?

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


[Tutor] Fw: Border width of Canvas widget in tkinter

2012-09-19 Thread Alok Joshi
Thanks very much Peter for your explanation and specially for your hint as to 
how I might debug these kinds of issues.
 
This is my first time asking a question on tutor mailing list and getting a 
reply. I hope this reply will correctly tie up as a response to your posting.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: Border width of Canvas widget in tkinter

2012-09-19 Thread Dwight Hutto
On Wed, Sep 19, 2012 at 7:55 AM, Alok Joshi  wrote:
> Thanks very much Peter for your explanation and specially for your hint as
> to how I might debug these kinds of issues.
>
> This is my first time asking a question on tutor mailing list and getting a
> reply. I hope this reply will correctly tie up as a response to your
> posting.
>

Just as a brief note, even though there are very knowledgeable, and
qualified individuals to answer on this list, you might find the
Tkinter mailing list a little more helpful.

I try to ask my questions in specific forums/mailing lists, and you
usually get better responses from a specific list just for that topic.

Here's the link:

http://mail.python.org/mailman/listinfo/tkinter-discuss

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: Border width of Canvas widget in tkinter

2012-09-19 Thread Dwight Hutto
Also, you might find the tkdocs handy:

http://www.tkdocs.com/tutorial/canvas.html

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Gregory Lund
>
> Your lack of response in the previous thread
>
> http://mail.python.org/pipermail/tutor/2012-August/090742.html
>
> is not a big motivation to answer this one.

I didn't have any response to post, I got the basics to work using a
hint from a colleague in and was able to grade the assignment, however
it seems as though the way the files are NOW saved in the Learning
Management System are not as I prepared my testing situation.
I wasn't able to use what Peter provided because I didn't understand
it (again, rookie/neophyte).
To an intermediate user, you most likely answered my questions, but I
didn't understand what you were saying/writing/typing.
It was full of code that I didn't (don't) understand (sys.argv, glob,
$ tree, etc.)
I had to go with what I could understand or at least work with. I
tried studying up on sys.argv, glob, etc. and got lost in the details)
Again, a colleague was able to help enough to get it to work using my
simplified code. (or at least code I could read).

>>
>> originalzip.zip
>> --originalfolder
>>   --folder1 (w/ two zip folders)
>> --internalzip1_a.zip
>> --internalfolder1_a
>>   --files
>>   --folders
>> --internalzip1_b.zip
>> --internalfolder1_b
>>   --files
>>   --folders
>>   --folder2 (w/1 zip folder)
>> --internalzip2.zip
>> --internalfolder2
>>   --files
>>   --folders
>>   --etc

I attempted to replicate Peter's 'Folder Structure' diagram above, he
did a better job 'drawing it' but the one above is my data situation.
Using my sample data, this is what the folder structure resembles below.

|__ Student_Work_Sample_use (a folder I create before running the
script, the original zip is placed in this folder before running the
script)
  |__originalzip.zip (entire class all zipped up into one) (THIS
NEEDS TO BE UNZIPPED IN THE CODE)
  |__Lab_2 (a folder that is the contents of originalzip.zip unzipped)
  |__aforker (unzipped folder that comes in Lab_2)
  |__aforker_lab_2.zip (student username 'aforker''s' lab)
(THIS NEEDS TO BE UNZIPPED IN THE CODE)
  |__aforker_lab_writeup.docx (a docx file that may or may
not come in with the lab submission (it may or may not be zipped, if
it's not zipped, no need to deal with it)
  |__aforker_lab_2 (a folder that is the contents of
aforker_lab_2.zip, unzipped)
   |__ datafolder (unzipped folders within aforkers
lab folder) (no need to worry about, just here for reference)
   |__ mapsfolder (unzipped folders within aforkers
lab folder) (no need to worry about, just here for reference)
  |__awilliams (unzipped folder that comes in Lab_2)
  |__awilliams_lab_2.zip (student username 'awilliams''s'
lab) (THIS NEEDS TO BE UNZIPPED IN THE CODE)
  |__awilliams_lab_2 (a folder that is the contents of
awilliams_lab_2.zip, unzipped)
   |__ datafolder (unzipped folders within awilliams
lab folder) (no need to worry about, just here for reference)
   |__ mapsfolder (unzipped folders within awilliams
lab folder) (no need to worry about, just here for reference)
  |__awilliams_lab_2_RESUB.zip (student username
'awilliams''s' lab) (THIS NEEDS TO BE UNZIPPED IN THE CODE)
  |__awilliams_lab_2_RESUB (a folder that is the contents
of awilliams_lab_2_RESUB.zip, unzipped)
   |__ datafolder (unzipped folders within awilliams
lab folder) (no need to worry about, just here for reference)
   |__ mapsfolder (unzipped folders within awilliams
lab folder) (no need to worry about, just here for reference)
  |__jsmith (unzipped folder that comes in Lab_2)
  |__jsmith_lab_2.zip (student username 'jsmith''s' lab)
(THIS NEEDS TO BE UNZIPPED IN THE CODE)
  |__jsmith_lab_2 (a folder that is the contents of
jsmith_lab_2.zip, unzipped)
   |__ datafolder (unzipped folders within jsmith lab
folder) (no need to worry about, just here for reference)
   |__ mapsfolder (unzipped folders within jsmith lab
folder) (no need to worry about, just here for reference)
  |__ etc. etc. etc. up to 40 students.

>>
>> My goal is to:
>> a) Unzip the 'originalzip.zip'
>> b) go to the 'originalfolder' (the unzipped version of the
>> originalzip.zip) c) go into the first folder (folder1) in the original
>> folder and unzip any and all zipfiles within it
>> d) go to the second folder (folder2) in the original folder and unzip
>> any and all zipfiles within it
>> e) continue until all folders within originalfolders have been checked
>> for internalzips
>>
>>
>> I have some code that works to extract the 'originalzip.zip', to an
>> 'originalfolder' but it won't go to the folders (folder1, folder2,
>> etc.) to unzip the zipfiles within them.
>> It gets hung up on access to the first student folder and won't unzip it.
>
> Hm, I would have expeced an exception. Perhaps you s

Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Steven D'Aprano

Hi Gregory,

On 20/09/12 01:10, Gregory Lund wrote:


Your lack of response in the previous thread

http://mail.python.org/pipermail/tutor/2012-August/090742.html

is not a big motivation to answer this one.


I didn't have any response to post, I got the basics to work using a
hint from a colleague in and was able to grade the assignment,

[...]

To an intermediate user, you most likely answered my questions, but I
didn't understand what you were saying/writing/typing.
It was full of code that I didn't (don't) understand (sys.argv, glob,
$ tree, etc.)


That's fine and nothing to be ashamed of. But don't be shy about asking
for explanations of what code does. If you're here to learn, you have
to ask questions!



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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Steven D'Aprano

Further comments below:


On 20/09/12 01:10, Gregory Lund wrote:


Have you considered the simpler code I gave in

http://mail.python.org/pipermail/tutor/2012-August/090743.html

before prodding on?


Yes, I did consider it, but I didn't understand it enough to 'run with it'.
If it worked perfectly I still wouldn't of understood it, and it I
needed to tweak it, there would have been no way for me to figure out
what to do to make it fit my scenario.
While it may be 'simpler' for the experienced python coder, Not being
familiar with Python, it wasn't simpler for me, I could hardly read
any of it.
I even printed it out and saved, but I couldn't understand it and
didn't want to bother you with it any more (felt like an idiot, to be
honest) (you would of had to explain everything, as I didn't
understand hardly any of it)


That's what we're here for! Don't be shy about asking questions.

However, I have to say Peter was a bit optimistic in his assumptions about
your general level of expertise. He mixed Python code and (probably) Linux
shell commands and output, which probably didn't help.

Using Peter's code, if you create a plain text file called "unzip_twice.py" 
containing:


import glob
import os
import sys
import zipfile

source_file = sys.argv[1]
dest_folder = sys.argv[2]

zipfile.ZipFile(source_file).extractall(dest_folder)

inner_zips_pattern = os.path.join(dest_folder, "*.zip")
for filename in glob.glob(inner_zips_pattern):
inner_folder = filename[:-4]
zipfile.ZipFile(filename).extractall(inner_folder)


and then run it from the shell like this:

python unzip_twice.py NAME-OF-ZIP-FILE NAME-OF-FOLDER-TO-EXTRACT-TO

(the folder must already exist), it may do what you want. Make sure
you test it on a sample set of data, not the real thing.

You'll also need to make sure that you have write permission to the
folder, and read permission to the zip file. If you get Permission
Denied errors, check the permissions.

I see that you're using Windows. I don't have Windows myself, but I
think you'll probably have fewer problems with pathnames if you use
forward slashes instead of backslashes. So:

D:/D_Drive_Documents/Student_Work_Sample_use/Lab_2/aforker/

Good luck and don't worry about asking dumb questions, the only dumb
question is "Was it you or your brother that was killed in the war?"

:-)


--
Steven

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Gregory Lund
> Using Peter's code, if you create a plain text file called "unzip_twice.py"
> containing:
>
>
> import glob
> import os
> import sys
> import zipfile
>
> source_file = sys.argv[1]
> dest_folder = sys.argv[2]
>
> zipfile.ZipFile(source_file).extractall(dest_folder)
>
> inner_zips_pattern = os.path.join(dest_folder, "*.zip")
> for filename in glob.glob(inner_zips_pattern):
> inner_folder = filename[:-4]
> zipfile.ZipFile(filename).extractall(inner_folder)
>
Consider it done, i have a new .py file saved as 'unzip_twice.py'
pasted below:

import glob
import os
import sys
import zipfile

source_file = sys.argv[1]
dest_folder = sys.argv[2]

zipfile.ZipFile(source_file).extractall(dest_folder)

inner_zips_pattern = os.path.join(dest_folder, "*.zip")
for filename in glob.glob(inner_zips_pattern):
inner_folder = filename[:-4]
zipfile.ZipFile(filename).extractall(inner_folder)

>
> and then run it from the shell like this:
>
> python unzip_twice.py NAME-OF-ZIP-FILE NAME-OF-FOLDER-TO-EXTRACT-TO
>
In the IDLE 2.6.5 shell I typed (exactly what is in quotes, without
quotes of course):  "python unzip_twice.py 2012-09-18 Lab_2.zip
Student_Work_Sample_usecopy1"
where  '2012-09-18 Lab_2.zip' was/is the original zipfile and
'Student_Work_Sample_usecopy1' is the folder in which I want it all
housed/extracted

I got what is in quotes below:
"IDLE 2.6.5
>>> python unzip_twice.py 2012-09-18 Lab_2.zip Student_Work_Sample_usecopy1
SyntaxError: invalid syntax"
(unzip_twice) was the highlighted invalid syntax

I tried again:
In the IDLE 2.6.5 shell I typed (exactly what is in quotes, without
quotes of course):  "unzip_twice.py 2012-09-18 Lab_2.zip
Student_Work_Sample_usecopy1"
where  '2012-09-18 Lab_2.zip' was/is the original zipfile and
'Student_Work_Sample_usecopy1' is the folder in which it exists and I
want it all housed/extracted

I got what is in quotes below:
"IDLE 2.6.5
>>> unzip_twice.py 2012-09-18 Lab_2.zip Student_Work_Sample_usecopy1
SyntaxError: invalid syntax"
(2012) was the highlighted 'invalid syntax'

Maybe its the version of Python?
Maybe I didn't read what you wrote to type into the shell properly?
Maybe it's the spaces and dashes in the zipfile name? (the LMS does
that (learning Management system)


> (the folder must already exist), it may do what you want. Make sure
> you test it on a sample set of data, not the real thing.
I created copies of my original test data and folders:
'Student_Work_Sample_usecopy1' was the folder and w/in it: the actual
zipfile.

>
> I see that you're using Windows. I don't have Windows myself, but I
> think you'll probably have fewer problems with pathnames if you use
> forward slashes instead of backslashes. So:
>
> D:/D_Drive_Documents/Student_Work_Sample_use/Lab_2/aforker/
>
yes, Windows 7, but I didn't type out the slashes, they were coming in
via what the code was running.
I couldn't figure out where to ensure that they were forward (or
double backslashes).
> Good luck and don't worry about asking dumb questions, the only dumb
> question is "Was it you or your brother that was killed in the war?"

Thanks, as you can tell, I need it!
Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Gregory Lund
more info:


> Consider it done, i have a new .py file saved as 'unzip_twice.py'
but it would be easier (the whole purpose of this task) is to have a
stand alone script that would work without having to open up the
shell.
In ArcGIS, I call the script by double clicking on my tool, selecting
the .zip in a GUI and it runs, extracting the first zipfile, but hangs
on the next, supposedly because of 'permissions' but 'permissions'
were not really an issue.
I think it's the "is it a .zip or is it not a zip" issue.
Permissions were not an issue in the original task, which worked (but
had flawed data structure (my fault)).


> Maybe its the version of Python?
> Maybe I didn't read what you wrote to type into the shell properly?
> Maybe it's the spaces and dashes in the zipfile name? (the LMS does
> that (learning Management system)
Maybe it's the location of the unzip_twice.py script?


>> (the folder must already exist), it may do what you want. Make sure
>> you test it on a sample set of data, not the real thing.
yes, folder existed

>> Good luck and don't worry about asking dumb questions, the only dumb
>> question is "Was it you or your brother that was killed in the war?"
>
> Thanks, as you can tell, I need it!
Thanks again, I really do need it! (oh sorry, was that obvious? haha!)

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Peter Otten
Gregory Lund wrote:

>> Using Peter's code, if you create a plain text file called
>> "unzip_twice.py" containing:
>>
>>
>> import glob
>> import os
>> import sys
>> import zipfile
>>
>> source_file = sys.argv[1]
>> dest_folder = sys.argv[2]
>>
>> zipfile.ZipFile(source_file).extractall(dest_folder)
>>
>> inner_zips_pattern = os.path.join(dest_folder, "*.zip")
>> for filename in glob.glob(inner_zips_pattern):
>> inner_folder = filename[:-4]
>> zipfile.ZipFile(filename).extractall(inner_folder)
>>
> Consider it done, i have a new .py file saved as 'unzip_twice.py'
> pasted below:
> 
> import glob
> import os
> import sys
> import zipfile
> 
> source_file = sys.argv[1]
> dest_folder = sys.argv[2]
> 
> zipfile.ZipFile(source_file).extractall(dest_folder)
> 
> inner_zips_pattern = os.path.join(dest_folder, "*.zip")
> for filename in glob.glob(inner_zips_pattern):
> inner_folder = filename[:-4]
> zipfile.ZipFile(filename).extractall(inner_folder)
> 
>>
>> and then run it from the shell like this:
>>
>> python unzip_twice.py NAME-OF-ZIP-FILE NAME-OF-FOLDER-TO-EXTRACT-TO
>>
> In the IDLE 2.6.5 shell I typed (exactly what is in quotes, without

Don't use Idle, follow the instructions on

http://www.windows7hacker.com/index.php/2009/08/how-to-open-dos-prompt-command-here-in-windows-7-and-more/

If you see the ugly little black window you are there an can type in your 
command.

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


[Tutor] interface with libreoffice calc spreadsheet to export pdf reports

2012-09-19 Thread Jim Smith Sr.
I have a spreadsheet with a named range "pdfReport" to export
to pdf in the default location.  The data changed based on student
number input to another named range "_pid".

Assumptions:  the spreadsheet is already open and on the correct
sheet.  This doesn't matter, as we will be selecting the cell and the
print range anyway.

So I need to do something similar to:

howmany = 16  # number of students to process

for c from 1 to howmany  # begin loop

select _pid
typein c  and press enter  # this changes the data in the report
select _filename# this is a cell which has a new
filename for each report
copy cell# this gives me the filename to
paste later
select pdfReport# select the range to export

# the menu choices are  File>Export as PDF>
# then the next dialog box gives choices but the only
# choice I want is in General (default tab)
# Range has All selected, I want Selection selected
# then Export or Enter pressed
#This is followed by a prompt for file name
Paste filename from above
Export

next c

ideally, my first task would be to copy a cell or pass a variable
containing the number "howmany"
so this would work for any of my classes.

Thanks in advance for getting me started with this.  I'm in the process
of learning python from
the excellent tutorial at Learn Pyton the Hard Way
   Although, it is not
really the hard way, but rather
quite simple but time consuming for someone unfamiliar with Python and
the UNO Basic dispatch of
both OpenOffice and LibreOffice.

Best Regards,
Jim



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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Peter Otten
Steven D'Aprano wrote:

> That's what we're here for! Don't be shy about asking questions.

Indeed. Also, Gregory, don't expect anything to work directly. Programming 
is mostly an iterative process where you write just a little bit of code 
before you have to stop to fix a host of bugs. Repeat until you have 
something that almost does what you intended...
 
> However, I have to say Peter was a bit optimistic in his assumptions about
> your general level of expertise. He mixed Python code and (probably) Linux
> shell commands and output, which probably didn't help.

Gregory introduced himself as a university lecturer, so I tacitly assumed 
that he had seen a shell window on a linux box or a mac, and would 
appreciate if he could use something familiar (globbing) in a new 
environment (python). 

I make similar assumptions about questioners' skills level all the time -- 
and sometimes fail in a big way ;)

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Gregory Lund
>>> and then run it from the shell like this:
On Wed, Sep 19, 2012 at 10:20 AM, Peter Otten <__pete...@web.de> wrote:
> Gregory Lund wrote:

>>> and then run it from the shell like this:
ahh, windows shell, not python shell.

from the directions Peter linked to, I shift-right clicked on the
folder where my script resided
(hope that was right)
then after
D:\D_Drive_Documents\Scripts\Unzip_a_zip_of_zips\Scripts>
I typed:python unzip_twice.py 2012-09-18 Lab_2.zip Student_Work_Sample_usecopy1
where:
unzip_twice.py is the script name as suggested by Steve
2012-09-18 Lab_2.zip is the zipfile
Student_Work_Sample_usecopy1 is the folder the zipfile resides and
where I want the info extracted to.

Lucky me... NOT...:-)
I got:
"'python' is not recognized as an internal or external command,
operable program or batch file" (without the quotes of course)

I am still worried that none of this will transfer to my GUI after I
get it working.
Is there a way to do this using the code that I started so that it
will work without the command prompt?
I got part of it to work, as detailed earlier, but... not the second
round of zips.

Maybe it can't be done?

Thanks for the continued help.
either way, once I get it to finally work, it will save me time.

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


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Gregory Lund
On Wed, Sep 19, 2012 at 10:40 AM, Peter Otten <__pete...@web.de> wrote:
> Steven D'Aprano wrote:
>
>> That's what we're here for! Don't be shy about asking questions.
>
> Indeed. Also, Gregory, don't expect anything to work directly. Programming
> is mostly an iterative process where you write just a little bit of code
> before you have to stop to fix a host of bugs. Repeat until you have
> something that almost does what you intended...

Believe me, I don't expect it to work directly, that's for sure.
I have just that, a little bit of code that extracts the first zip,
and am now working on a little bit of code to extract the zips within
it.
>
>> However, I have to say Peter was a bit optimistic in his assumptions about
>> your general level of expertise. He mixed Python code and (probably) Linux
>> shell commands and output, which probably didn't help.
>
> Gregory introduced himself as a university lecturer, so I tacitly assumed
> that he had seen a shell window on a linux box or a mac, and would
> appreciate if he could use something familiar (globbing) in a new
> environment (python).

You were correct, I have seen a shell window on a Windows box. Correct
Assumption.
However, I did not know it was that, to which you were referencing,
and it wouldn't of worked where I want it to:
In a GUI via ArcGIS.
>
> I make similar assumptions about questioners' skills level all the time --
> and sometimes fail in a big way ;)
Sorry, tried to emphasize the 'neophyte' from the get go.
Definition of crazy? Doing the same thing over and over again while
expecting different results?

Perhaps the code can not be written to run in a python shell (from
which I could use in my Esri ArcGIS GUI.
(again, I have a spot to put in one link to the .py code, the GUI asks
me (in a way) "which zipfile", I navigate to it and click 
I have no need for shortened code or running in the cmd window, it's
such a short operation, it doesn't matter if it takes me 100 to 1000
lines of 'baby' or 'rookie' code to write, as long as it works.
With only one starting zip and within it up to 40 folders each
containing (usually) one zipfile (max of 5), the matter of time it
takes to run is not an issue.
I just need to have one .py file that does it all, or calls upon other
.py files I guess in order to work.

I do appreciate the help, and am learning in this process.
again, maybe I want python to do something that can't be done?

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


[Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-19 Thread ashish makani
Hi PyTutor Folks

Here is my situation

1. I have two machines. Lets call them *local & remote.*
Both run ubuntu & both have python installed

2. I have a python script, *local.py*, running on *local *which needs to
pass arguments ( 3/4 string arguments, containing whitespaces like spaces,
etc ) to a python script, *remote.py* running on *remote* (the remote
machine).

I have the following questions:

1. What's the best way to accomplish my task ?
I have researched quite a bit & so far found really conflicting & complex
workarounds.

I googled & found people using several libraries to accomplish ssh to
remote machine & execute a command on remote machine.
paramiko  ( now forked into the ssh
moduke),
fabric ,
pushy,etc

People who have used any of these libraries, which one would you recommend,
as the most apt (simple & easy to use, lightweight, best performance, etc)
for my situation ?

2. I would prefer a solution, which does NOT require the installation of
extra libraries on the local & remote machines.
If installing external librar

3. Has anybody been able to do this using os.system ?

I tried this
>>> import os
>>> *os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")*
*
*
This worked, but if the arguments i tried to pass, had spaces, i was not
able to 'escape' the spaces.

Any & all explanations/links/code
snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor
community would be greatly appreciated.

Thanks a ton

cheers
ashish

email :
ashish.makani
domain:gmail.com

*“The only way to do great work is to love what you do. If you haven’t
found it yet, keep looking. Don’t settle. As with all matters of the heart,
you’ll know when you find it.” - Steve Jobs (1955 - 2011)*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-19 Thread Dave Angel
On 09/19/2012 02:47 PM, ashish makani wrote:
> Hi PyTutor Folks
>
> Here is my situation
>
> 1. I have two machines. Lets call them *local & remote.*
> Both run ubuntu & both have python installed
>
> 2. I have a python script, *local.py*, running on *local *which needs to
> pass arguments ( 3/4 string arguments, containing whitespaces like spaces,
> etc ) to a python script, *remote.py* running on *remote* (the remote
> machine).
>
> I have the following questions:
>
> 1. What's the best way to accomplish my task ?
> I have researched quite a bit & so far found really conflicting & complex
> workarounds.
>
> I googled & found people using several libraries to accomplish ssh to
> remote machine & execute a command on remote machine.
> paramiko  ( now forked into the ssh
> moduke),
> fabric ,
> pushy,etc
>
> People who have used any of these libraries, which one would you recommend,
> as the most apt (simple & easy to use, lightweight, best performance, etc)
> for my situation ?
>
> 2. I would prefer a solution, which does NOT require the installation of
> extra libraries on the local & remote machines.
> If installing external librar
>
> 3. Has anybody been able to do this using os.system ?
>
> I tried this
 import os
 *os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")*
> *
> *
> This worked, but if the arguments i tried to pass, had spaces, i was not
> able to 'escape' the spaces.
>
> Any & all explanations/links/code
> snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor
> community would be greatly appreciated.
>
> Thanks a ton
>
> cheers
> ashish
>
> email :
> ashish.makani
> domain:gmail.com
>
> *“The only way to do great work is to love what you do. If you haven’t
> found it yet, keep looking. Don’t settle. As with all matters of the heart,
> you’ll know when you find it.” - Steve Jobs (1955 - 2011)*
>
>

Since you prefer not installing any optional libraries, I'll just talk
about your os.system() mechanism. Is that adequate for you, other than
the problem with spaces?

If so, then why not test it with the real ssh, to figure out where the
quotes need to be to handle the spaces. Then once you have it working,
use single quotes around the whole thing when calling os.exec().

Something like (all untested):

os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has spaces" 
arg3')


Or, more likely, build the arguments in separate variables, and use

os.system( 'ssh remoteuser@remote python remote.py "%s" "%s" "%s"' %
(arg1, arg2, arg3) )

that will fail if the argn already has quotes in it. You can get much
fancier with encoding, which will add backslashes in front of some
characters, etc. But keep it simple if you can.

I ought to give the obligatory: use the multiprocess module instead of
os.exec, but if something works for you, I'm not going to argue.




-- 

DaveA

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


Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-19 Thread ashish makani
Thanks a ton for the prompt reply & the great suggestions, Dave.

1.   A colleague gave this exact same suggestion
os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has spaces"
arg3')

I was thinking spaces is my problem, so i initially tested the following
(no ssh)
os.system('python remote.py arg1 "arg 2 has spaces" arg3')  & it works :)

But sadly,  os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2
has spaces" arg3')   does not :(

2. Also, you mentioned os.exec
Which would you recommend ?
os.system or os.exec ?

Thanks a lot,

cheers
ashish



On Thu, Sep 20, 2012 at 12:54 AM, Dave Angel  wrote:

> On 09/19/2012 02:47 PM, ashish makani wrote:
> > Hi PyTutor Folks
> >
> > Here is my situation
> >
> > 1. I have two machines. Lets call them *local & remote.*
> > Both run ubuntu & both have python installed
> >
> > 2. I have a python script, *local.py*, running on *local *which needs to
> > pass arguments ( 3/4 string arguments, containing whitespaces like
> spaces,
> > etc ) to a python script, *remote.py* running on *remote* (the remote
> > machine).
> >
> > I have the following questions:
> >
> > 1. What's the best way to accomplish my task ?
> > I have researched quite a bit & so far found really conflicting & complex
> > workarounds.
> >
> > I googled & found people using several libraries to accomplish ssh to
> > remote machine & execute a command on remote machine.
> > paramiko  ( now forked into the ssh
> > moduke),
> > fabric ,
> > pushy,etc
> >
> > People who have used any of these libraries, which one would you
> recommend,
> > as the most apt (simple & easy to use, lightweight, best performance,
> etc)
> > for my situation ?
> >
> > 2. I would prefer a solution, which does NOT require the installation of
> > extra libraries on the local & remote machines.
> > If installing external librar
> >
> > 3. Has anybody been able to do this using os.system ?
> >
> > I tried this
>  import os
>  *os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")*
> > *
> > *
> > This worked, but if the arguments i tried to pass, had spaces, i was not
> > able to 'escape' the spaces.
> >
> > Any & all explanations/links/code
> > snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python
> tutor
> > community would be greatly appreciated.
> >
> > Thanks a ton
> >
> > cheers
> > ashish
> >
> > email :
> > ashish.makani
> > domain:gmail.com
> >
> > *“The only way to do great work is to love what you do. If you haven’t
> > found it yet, keep looking. Don’t settle. As with all matters of the
> heart,
> > you’ll know when you find it.” - Steve Jobs (1955 - 2011)*
> >
> >
>
> Since you prefer not installing any optional libraries, I'll just talk
> about your os.system() mechanism. Is that adequate for you, other than
> the problem with spaces?
>
> If so, then why not test it with the real ssh, to figure out where the
> quotes need to be to handle the spaces. Then once you have it working,
> use single quotes around the whole thing when calling os.exec().
>
> Something like (all untested):
>
> os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has
> spaces" arg3')
>
>
> Or, more likely, build the arguments in separate variables, and use
>
> os.system( 'ssh remoteuser@remote python remote.py "%s" "%s" "%s"' %
> (arg1, arg2, arg3) )
>
> that will fail if the argn already has quotes in it. You can get much
> fancier with encoding, which will add backslashes in front of some
> characters, etc. But keep it simple if you can.
>
> I ought to give the obligatory: use the multiprocess module instead of
> os.exec, but if something works for you, I'm not going to argue.
>
>
>
>
> --
>
> DaveA
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-19 Thread Dave Angel
On 09/19/2012 03:45 PM, ashish makani wrote:
> Thanks a ton for the prompt reply & the great suggestions, Dave.
> 

Please don't top post.  In this mailing list, the convention is to put
your remarks after the part you're quoting (which usually isn't the
entire message).  That way, if the context gets complex, it's easier to
see who wrote what, and in what order.

> 1.   A colleague gave this exact same suggestion
> os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2 has spaces"
> arg3')
> 
> I was thinking spaces is my problem, so i initially tested the following
> (no ssh)
> os.system('python remote.py arg1 "arg 2 has spaces" arg3')  & it works :)
> 
> But sadly,  os.system ('ssh remoteuser@remote python remote.py arg1 "arg 2
> has spaces" arg3')   does not :(

Did you try it the way I suggested above?  Make it work in ssh, then
worry about how python can build that command string.

> 
> 2. Also, you mentioned os.exec
> Which would you recommend ?
> os.system or os.exec ?

Since there's no  os.exec, it was just an brain-hiccup on my part.



So, back to the problem.  Once you've got it working in ssh, then we can
figure how to make os.exec, or other python execution mechanism, work.

-- 

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


[Tutor] RTF ( Rich Text) module for Python

2012-09-19 Thread Christopher Barnes
Hi All,

Thanks in advance for any help or suggestions. I'm new to python. Does
anyone have any suggestions for a RTF ( RichText) python module to use to
create RTF documents. I have tried to use PyRTF, but am struggling. It
seems the PyRTF project hasn't had any updates in a while and Ive had
a difficult time following the examples. Anyhow, if you have any thoughts
I'm glad to hear them.


Thanks,

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


Re: [Tutor] Passing arguments to & running a python script on a remote machine from a python script on local machine .

2012-09-19 Thread eryksun
On Wed, Sep 19, 2012 at 2:47 PM, ashish makani  wrote:
>
> I tried this
 import os
 os.system ("ssh remoteuser@remote python remote.py arg1 arg2 arg3")
>
> This worked, but if the arguments i tried to pass, had spaces, i was not
> able to 'escape' the spaces.

Presuming "remote" has an SSH server running, and that a firewall
isn't blocking port 22, and that you've enabled logging in without a
password (i.e. ssh-keygen), try the following:

import sys
import subprocess

user = remoteuser
hostname = remote
cmd = 'python remote.py "%s" "%s" "%s"' % (arg1, arg2, arg3)

try:
out = subprocess.check_output(['ssh', '%s@%s' % (user, hostname), cmd])
except subprocess.CalledProcessError as e:
print >>sys.stderr, str(e)   # handle/log the error, retry
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.

2012-09-19 Thread Oscar Benjamin
On 19 September 2012 19:00, Gregory Lund  wrote:

> >>> and then run it from the shell like this:
> On Wed, Sep 19, 2012 at 10:20 AM, Peter Otten <__pete...@web.de> wrote:
> > Gregory Lund wrote:
>
> >>> and then run it from the shell like this:
> ahh, windows shell, not python shell.
>
> from the directions Peter linked to, I shift-right clicked on the
> folder where my script resided
> (hope that was right)
> then after
> D:\D_Drive_Documents\Scripts\Unzip_a_zip_of_zips\Scripts>
> I typed:python unzip_twice.py 2012-09-18 Lab_2.zip
> Student_Work_Sample_usecopy1
> where:
> unzip_twice.py is the script name as suggested by Steve
> 2012-09-18 Lab_2.zip is the zipfile
> Student_Work_Sample_usecopy1 is the folder the zipfile resides and
> where I want the info extracted to.
>
> Lucky me... NOT...:-)
> I got:
> "'python' is not recognized as an internal or external command,
> operable program or batch file" (without the quotes of course)
>

You need to add the folder where python.exe is to your PATH variable.

First you need to find the folder where python is on your computer. You can
do this from within a python script using the following two lines:
import sys
print sys.executable

Once you've found the folder containing python.exe, add that folder to your
PATH variable:
http://code.google.com/p/tryton/wiki/AddingPythonToWindowsPath
http://showmedo.com/videotutorials/video?name=96&fromSeriesID=96

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