Re: [Tutor] Need help with python script

2014-08-04 Thread P McCombs
Sorry, I missed copying this to the list.

On Aug 4, 2014 8:13 AM, "P McCombs"  wrote:
>
>
> On Jul 31, 2014 4:50 PM, "McKinley, Brett D."  wrote:
> >
> > I would like to see if someone can help me with a python script.  I’m
trying to export a file geodatabase feature class to csv file.  This is
what I have so far:
>
> Does the code you attached execute successfully?
> Are you running this as a tool,  or from the command line?
> Be cautioned that arcpy is outside the scope of this mailing list,  but
it won't have much to do with your questions at first.
>
> >
> >
> > import arcpy
> >
> > import os
> >
> > import csv
> >
> > import domainvalues
> >
> >
> >
> >
> >
> > def export_to_csv(dataset, output, dialect):
> >
> > """Output the data to a CSV file"""
> >
> > # create the output writer
> >
> > out_writer = csv.writer(open(output, 'wb'), dialect=dialect)
> >
> > # return the list of field names and field values
> >
> > header, rows = domainvalues.header_and_iterator(dataset)
> >
> >
> >
> > # write the field names and values to the csv file
> >
> > out_writer.writerow(map(domainvalues._encodeHeader, header))
> >
> > for row in rows:
> >
> > out_writer.writerow(map(domainvalues._encode, row))
> >
> >
> >
> > if __name__ == "__main__":
> >
> > # Get parameters
> >
> > dataset_name = arcpy.GetParameterAsText(0)
> >
> > output_file = arcpy.GetParameterAsText(1)
> >
> > delim = arcpy.GetParameterAsText(2).lower()
> >
> > dialect = 'excel'
> >
> > if delim == 'comma':
> >
> > pass
> >
> > else:
> >
> > dialect = 'excel-tab'
> >
> > try:
> >
> > export_to_csv(dataset_name, output_file, dialect)
> >
> > except Exception as err:
> >
> > arcpy.AddError('Error: {0}'.format(err))
> >
> >
> >
> >
> >
> > I would like for the script to export only certain fields and also
export only the newest records.  As for now, it’s exporting everything.
> >
>
> It is best to try to add one new feature on your own and attach the
result. You will get the best feedback that way.
>
> >
> >
> > Thanks
> >
> > Brett McKinley
> >
> >
> >
> >
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> >https://mail.python.org/mailman/listinfo/tutor
> >
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help with python script

2014-08-04 Thread Joel Goldstick
On Mon, Aug 4, 2014 at 11:20 AM, P McCombs  wrote:
> Sorry, I missed copying this to the list.
>
> On Aug 4, 2014 8:13 AM, "P McCombs"  wrote:
>
>
>>
>>
>> On Jul 31, 2014 4:50 PM, "McKinley, Brett D."  wrote:
>> >
>> > I would like to see if someone can help me with a python script.  I’m
>> > trying to export a file geodatabase feature class to csv file.  This is 
>> > what
>> > I have so far:
>>
>> Does the code you attached execute successfully?
>> Are you running this as a tool,  or from the command line?
>> Be cautioned that arcpy is outside the scope of this mailing list,  but it
>> won't have much to do with your questions at first.
>
>>
>> >
>> >
>> > import arcpy
>> >
>> > import os
>> >
>> > import csv
>> >
>> > import domainvalues
>> >
>> >
>> >
>> >
>> >
>> > def export_to_csv(dataset, output, dialect):
>> >
>> > """Output the data to a CSV file"""
>> >
>> > # create the output writer
>> >
>> > out_writer = csv.writer(open(output, 'wb'), dialect=dialect)
>> >
>> > # return the list of field names and field values
>> >
>> > header, rows = domainvalues.header_and_iterator(dataset)
>> >
>> >
>> >
>> > # write the field names and values to the csv file
>> >
>> > out_writer.writerow(map(domainvalues._encodeHeader, header))
>> >
>> > for row in rows:

before you write row, you need to examine the appropriate fields to
filter out the fields you don't want, and order the rows by whichever
field determines newness.
Also, you probably want to output your header row to only include
columns you wish to write
>> >
>> > out_writer.writerow(map(domainvalues._encode, row))
>> >
>> >
>> >
>> > if __name__ == "__main__":
>> >
>> > # Get parameters
>> >
>> > dataset_name = arcpy.GetParameterAsText(0)
>> >
>> > output_file = arcpy.GetParameterAsText(1)
>> >
>> > delim = arcpy.GetParameterAsText(2).lower()
>> >
>> > dialect = 'excel'
>> >
>> > if delim == 'comma':
>> >
>> > pass
>> >
>> > else:
>> >
>> > dialect = 'excel-tab'
>> >
>> > try:
>> >
>> > export_to_csv(dataset_name, output_file, dialect)
>> >
>> > except Exception as err:
>> >
>> > arcpy.AddError('Error: {0}'.format(err))
>> >
>> >
>> >
>> >
>> >
>> > I would like for the script to export only certain fields and also
>> > export only the newest records.  As for now, it’s exporting everything.
>> >
>>
>> It is best to try to add one new feature on your own and attach the
>> result. You will get the best feedback that way.
>>
>> >
>> >
>> > Thanks
>> >
>> > Brett McKinley
>> >
>> >
>> >
>> >
>> >
>> >
>> > ___
>> > Tutor maillist  -  Tutor@python.org
>> > To unsubscribe or change subscription options:
>> >https://mail.python.org/mailman/listinfo/tutor
>> >
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



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


[Tutor] Python; webcam

2014-08-04 Thread René Mathieu
Hello there

I'm writing a Python program and I would like to display a video device
(webcam). How should I write in the program?

thank you very much

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


[Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Greg Markham
Hello,

I'm extremely new to Python having only just started learning this week.
I'm slowly plodding through a book, Python Programming for the Absolute
Beginner, 3rd ed

by Michael Dawson.

Code is provided for all the scripts found throughout the book (found here
),
but I'm running into a syntax error when running one of the unmodified
programs.  On line 14, which reads:

*print("Here", end=" ")*

I'm receiving a *syntax error* which points to the *end *parameter.  In
order to confirm this, I modified the code to read:

*print("Here ")*

...which runs without incident.  My best guess is that there's a minor
difference between the version of Python I'm using (3.4.1) and that which
was in use at the time the book was written (3.1.x) that is responsible for
this error.

Thanks and my apologies for the "greenness" of this question.

Sincerely,

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


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Joel Goldstick
On Mon, Aug 4, 2014 at 1:28 PM, Greg Markham  wrote:
> Hello,
>
> I'm extremely new to Python having only just started learning this week.
> I'm slowly plodding through a book, Python Programming for the Absolute
> Beginner, 3rd ed by Michael Dawson.
>
> Code is provided for all the scripts found throughout the book (found here),
> but I'm running into a syntax error when running one of the unmodified
> programs.  On line 14, which reads:
>
> print("Here", end=" ")
>
> I'm receiving a syntax error which points to the end parameter.  In order to
> confirm this, I modified the code to read:
>
> print("Here ")
>
> ...which runs without incident.  My best guess is that there's a minor
> difference between the version of Python I'm using (3.4.1) and that which
> was in use at the time the book was written (3.1.x) that is responsible for
> this error.

Welcome to the group.  I think you made a typo.  Your code should run.
I just tried this:
>>> print("hi", end=" ")
hi >>>

A couple of things that will make it easier to help:

1. send mail as plain text.  Rich text causes some readers problems
2. copy and paste the code and complete traceback.  retyping things
make it more likely that what is in your code isn't exactly what you
typed

>
> Thanks and my apologies for the "greenness" of this question.

No apologies necessary -- ask away
>
> Sincerely,
>
> Greg
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Danny Yoo
> > but I'm running into a syntax error when running one of the unmodified
> > programs.  On line 14, which reads:
> >
> > print("Here", end=" ")
> >
> > I'm receiving a syntax error which points to the end parameter.

I'd like to also support Joel's suggestion to provide detailed output of
the error message.  It will help.

> > difference between the version of Python I'm using (3.4.1) and that
which
> > was in use at the time the book was written (3.1.x) that is responsible
for
> > this error.

Just to double check: how are you confirming what version of Python you're
using?

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


Re: [Tutor] Python; webcam

2014-08-04 Thread Danny Yoo
On Mon, Aug 4, 2014 at 7:10 AM, René Mathieu  wrote:
> Hello there
>
> I'm writing a Python program and I would like to display a video device
> (webcam). How should I write in the program?


Hi Mathieu René,

I'm unsure because I have no direct experience with this.  You might
want to check the general Python mailing list if you don't get other
answers from the tutors here.

There is no built-in support in the Standard LIbrary to a webcam;
however, there appear to be external libraries that provide access  to
a webcam.  From a web search, it looks like the Pygame library might
be applicable:
http://www.pygame.org/docs/tut/camera/CameraIntro.html.  You might
also be able to look into the PythonCV library:
http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python; webcam

2014-08-04 Thread Vipul Sharma
You should try Computer Vision libraries for python like OpenCV and
SimpleCV. They are best for playing with the camera, videos and for image
processing tasks. My personal favorite is OpenCV you should definitely try
it.
https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_intro/py_intro.html#intro


On Tue, Aug 5, 2014 at 2:25 AM, Danny Yoo  wrote:

> On Mon, Aug 4, 2014 at 7:10 AM, René Mathieu 
> wrote:
> > Hello there
> >
> > I'm writing a Python program and I would like to display a video device
> > (webcam). How should I write in the program?
>
>
> Hi Mathieu René,
>
> I'm unsure because I have no direct experience with this.  You might
> want to check the general Python mailing list if you don't get other
> answers from the tutors here.
>
> There is no built-in support in the Standard LIbrary to a webcam;
> however, there appear to be external libraries that provide access  to
> a webcam.  From a web search, it looks like the Pygame library might
> be applicable:
> http://www.pygame.org/docs/tut/camera/CameraIntro.html.  You might
> also be able to look into the PythonCV library:
>
> http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Vipul Sharma
Jabalpur Engineering College
+91-8827931450
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Cameron Simpson

On 04Aug2014 13:38, Danny Yoo  wrote:

> difference between the version of Python I'm using (3.4.1) and that which
> was in use at the time the book was written (3.1.x) that is responsible
> for this error.


Just to double check: how are you confirming what version of Python you're
using?


In particular, Python 2 will produce a syntax error for your print statement; 
Python 3 should work.


Show a short transcript which also shows your ptyhon version.

Example:

$ python
Python 2.7.8 (default, Jul 13 2014, 17:11:32)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hi", end=" ")
  File "", line 1
print("hi", end=" ")
   ^
SyntaxError: invalid syntax

Versus:

$ python3.4
Python 3.4.1 (default, May 21 2014, 01:39:38)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hi", end=" ")
hi >>>

The "$" is my prompt.

Any Python 3 should accept your print() call.

The default system "python" on most platforms is still Python 2; that may be 
misleading you. In particular, if you're running a script you may need to 
ensure it is run with the correct Python version.


It is perfectly fine to have multiple Python versions installed, BTW. Just make 
sure you're using what you intend.


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


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Greg Markham
On Mon, Aug 4, 2014 at 12:37 PM, Alex Kleider  wrote:

> On 2014-08-04 10:28, Greg Markham wrote:
>
>> Hello,
>>
>> I'm extremely new to Python having only just started learning this week.
>> I'm slowly plodding through a book, Python Programming for the Absolute
>> Beginner, 3rd ed
>> > Edition/dp/1435455002/ref=sr_1_5?ie=UTF8&qid=1407049249&sr=
>> 8-5&keywords=learning+python>
>>
>> by Michael Dawson.
>>
>> Code is provided for all the scripts found throughout the book (found here
>> > 1435455002/downloads/py3e_source.zip>),
>>
>> but I'm running into a syntax error when running one of the unmodified
>> programs.  On line 14, which reads:
>>
>> *print("Here", end=" ")*
>>
> try
>
> print("Here", end="")
>
> (no space between the quotes)
> The end parameter defaults to newline.
> If you change it to the empty string, there'll be no output of a newline
> character.
>

As I understand it, newline is inferred unless the "end" parameter is
used.  This program is designed merely to illustrate the flexibility of the
print function.  As you'll see below, the output from the line in which I
was receiving an error is intended to read as, "Here it is..."  For
clarity, the full program reads as follows:


# Game Over - Version 2
# Demonstrates the use of quotes in strings
# Python Programming for the Absolute Beginner, 3rd ed - Ch 2
# Greg Markham - Aug 04, 2014

print("Program 'Game Over' 2.0")

print("Same", "message", "as before")

print("Just",
  "a bit",
  "bigger")

print("Here", end=" ")
print("it is...")

print(
"""
 _   ___   ___  ___   _
/  ___| /   | /   |/   | |  ___|
| |/ /| |/ /|   /| | | |__
| |  _/ ___ |   / / |__/ | | |  __|
| |_| |  / /  | |  / /   | | | |___
\_/ /_/   |_| /_/|_| |_|

 _   _ _   _   _
/  _  \ | |   / / |  ___| |  _  \
| | | | | |  / /  | |__   | |_| |
| | | | | | / /   |  __|  |  _  /
| |_| | | |/ /| |___  | | \ \
\_/ |___/ |_| |_|  \_\

"""
 )

input("\n\nPress the enter key to exit.")
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: New to Python - print function - invalid syntax

2014-08-04 Thread Greg Markham
On Mon, Aug 4, 2014 at 1:38 PM, Danny Yoo  wrote:

>
> > > but I'm running into a syntax error when running one of the unmodified
> > > programs.  On line 14, which reads:
> > >
> > > print("Here", end=" ")
> > >
> > > I'm receiving a syntax error which points to the end parameter.
>
> I'd like to also support Joel's suggestion to provide detailed output of
> the error message.  It will help.
>
Here is the full context of the error message:

 File "I:\Programming\Scripts\Learning\Chapter02\game_over2.py", line 14
print("Here", end=" ") #Modified from: print("Here", end=" ")
 ^
SyntaxError: invalid syntax


> > > difference between the version of Python I'm using (3.4.1) and that
> which
> > > was in use at the time the book was written (3.1.x) that is
> responsible for
> > > this error.
>
> Just to double check: how are you confirming what version of Python you're
> using?
>
>From command line, C:\> python -V


> Best of wishes!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Greg Markham
On Mon, Aug 4, 2014 at 11:52 AM, Joel Goldstick 
wrote:

> On Mon, Aug 4, 2014 at 1:28 PM, Greg Markham 
> wrote:
> > Hello,
> >
> > I'm extremely new to Python having only just started learning this week.
> > I'm slowly plodding through a book, Python Programming for the Absolute
> > Beginner, 3rd ed by Michael Dawson.
> >
> > Code is provided for all the scripts found throughout the book (found
> here),
> > but I'm running into a syntax error when running one of the unmodified
> > programs.  On line 14, which reads:
> >
> > print("Here", end=" ")
> >
> > I'm receiving a syntax error which points to the end parameter.  In
> order to
> > confirm this, I modified the code to read:
> >
> > print("Here ")
> >
> > ...which runs without incident.  My best guess is that there's a minor
> > difference between the version of Python I'm using (3.4.1) and that which
> > was in use at the time the book was written (3.1.x) that is responsible
> for
> > this error.
>
> Welcome to the group.  I think you made a typo.  Your code should run.
> I just tried this:
> >>> print("hi", end=" ")
> hi >>>
>

 Ok, when I try this from the Shell window, it works.  When executing the
full program from command line, it does not.  Python versions from both
shell and command line are 3.4.1 (confirmed via command: "python -V").

Full error msg output when run from cmd line reads:

  File "I:\Programming\Scripts\Learning\chapter02\game_over2.py", line 14
print("Here", end=" ")
 ^
SyntaxError: invalid syntax

A couple of things that will make it easier to help:
>
> 1. send mail as plain text.  Rich text causes some readers problems
>

Thanks for the tip.  I'll keep this in mind for future queries & replies.


> 2. copy and paste the code and complete traceback.  retyping things
> make it more likely that what is in your code isn't exactly what you
> typed
>

Apologies, but what is a traceback?  Is this a debugging feature found in
the shell?  (I looked, but didn't see it)

Thanks,

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


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Alan Gauld

On 05/08/14 00:21, Greg Markham wrote:


but I'm running into a syntax error


As others have said you are getting the expected error when running 
Python v3 code under Python v2.


How exactly are you running the program? It looks like somehow you
are picking up Python v2 when you run the script even though your python 
-V is showing v3.


BTW. Which OS are you using? It shouldn't affect the cause but
it helps with the debugging!


For clarity, the full program reads as follows:


# Game Over - Version 2
# Demonstrates the use of quotes in strings
# Python Programming for the Absolute Beginner, 3rd ed - Ch 2
# Greg Markham - Aug 04, 2014

print("Program 'Game Over' 2.0")

print("Same", "message", "as before")

print("Just",
   "a bit",
   "bigger")


Does all of the above print out correctly? Can you send
us a cut n paste of the exact output of the program?




print("Here", end=" ")
print("it is...")

print(
 """
  _   ___   ___  ___   _
 /  ___| /   | /   |/   | |  ___|
 | |/ /| |/ /|   /| | | |__
 | |  _/ ___ |   / / |__/ | | |  __|
 | |_| |  / /  | |  / /   | | | |___
 \_/ /_/   |_| /_/|_| |_|

  _   _ _   _   _
 /  _  \ | |   / / |  ___| |  _  \
 | | | | | |  / /  | |__   | |_| |
 | | | | | | / /   |  __|  |  _  /
 | |_| | | |/ /| |___  | | \ \
 \_/ |___/ |_| |_|  \_\

 """
  )

input("\n\nPress the enter key to exit.")


finally you could try putting the following at the very top of your program:

import sys
print(sys.version)

That will definitively prove that you are actually
running v3 on the file...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

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


Re: [Tutor] New to Python - print function - invalid syntax

2014-08-04 Thread Steven D'Aprano
On Mon, Aug 04, 2014 at 04:44:46PM -0700, Greg Markham wrote:

>  Ok, when I try this from the Shell window, it works.  When executing the
> full program from command line, it does not.  Python versions from both
> shell and command line are 3.4.1 (confirmed via command: "python -V").

I'm a little confused, because I consider "the shell" and "command line" 
to more or less be synonymous. Perhaps if you explain step-by-step what 
you do. Here's my guess of what you mean by "command line":

Click on Start Menu.
Choose "Run" command.
Enter "cmd.exe"
Enter "python I:\Programming\Scripts\Learning\chapter02\game_over2.py"

Am I close?

> Full error msg output when run from cmd line reads:
> 
>   File "I:\Programming\Scripts\Learning\chapter02\game_over2.py", line 14
> print("Here", end=" ")
>  ^
> SyntaxError: invalid syntax

That definitely looks like a Python 2 error, but it should work in any 
version of Python 3. This is a most perplexing error, I can only imagine 
that you have both Python 2 and 3 installed and somehow, for some 
unknown reason, you're sometimes getting one and sometimes getting the 
other.


> > 2. copy and paste the code and complete traceback.  retyping things
> > make it more likely that what is in your code isn't exactly what you
> > typed
> >
> 
> Apologies, but what is a traceback?  Is this a debugging feature found in
> the shell?  (I looked, but didn't see it)

A traceback is the text Python prints when an error occurs. It normally 
starts with the word "Traceback" and ends with the kind of error 
(SyntaxError, NameError, ImportError, etc.) and usually an error 
message. For example:

Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in function
TypeError: object of type 'int' has no len()

or similar. The details will differ slightly (e.g. sometimes Python can 
print the offending lines of code) but the important thing is that there 
is a lot of useful information available in the traceback, if you show 
us the entire thing, from start to finish.

SyntaxError is quite exceptional, in that it normally doesn't start with 
the word "Traceback", for technical reasons[1]. Technically, I suppose, 
it's not really a traceback, but we tend to call it such regardless.






[1] SyntaxError normally occurs at compile-time, while Python is parsing 
the source code, and before execution starts, so there's no chain of 
calling functions and no traceback. But we normally don't care about the 
technical details.


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