print console out to a txt or csv file

2019-02-10 Thread GISDude
Hi all,
I have been working on some code to list the files of a folder that has .pdf 
extension. I have the basic code to create a list, but it prints that list to 
the console. I'd like my code to write a txt file that contains that list (to 
later import into excel).

###A script to list pdf files in a folder
###gisdude 02/09/19
###
import os, sys, glob, csv, pathlib

###First, let's change the dir with os

os.chdir("C:\\Users\\Randy\\Documents\\BOOKS")

###Second, let's now get the list of files in this directory

files = glob.glob('*.pdf')
for file in glob.glob("*.pdf"):
print (file)

###This prints to the IDLE console
###But, I want to print to a csv file

for filename in glob.iglob ('*.pdf'):
###with open('Listofpdf', 'filename') as csvfile:
###writer = csv.writer(csvfile, delimter=' ', 
quotechar='|', quoting=csv.QUOTE_MINIMAL)
###writer.writerrow([('{}\t.format(elem))])
from pathlib import Path
searchdir = "C:\\Users\\Randy\\Documents\\BOOKS"
csvfilename = "listofpdf.txt"

with Path(csvfilename).open(mode="w+") as p:
files = Path(searchdir).glob('*.py')
p.write(f"{' '.join(str(file) for file in files)}\n")

At this point, the pathlib mod seems like it should create the file?

I'm on WINDOWS 10 and IDLE 3.7.

Thanks for any help,
R`









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


Re: pip and command line

2018-03-11 Thread GISDude
On Saturday, March 10, 2018 at 10:28:00 AM UTC-8, Terry Reedy wrote:
> On 3/10/2018 12:23 PM, GISDude wrote:
> > Hi all,
> > I'm hoping someone could help a wannabe python coder out. I'm an aspiring 
> > Data/AI/ML coder/programmer/datafiend - that might help with my situation.
> > 
> > In my various fits of python downloads, I've managed to download Anaconda, 
> 
> Anaconda is a cpython distribution that comes with various 3rd party 
> modules pre-installed.
> 
> > Pyscripter,
> 
> I am not familiar with this.
> 
> > IDLE(3.6/32 AND 64bit), IDLE 2.7.
> 
> If you are on Windows, you did not download 'IDLE'.  You downloaded 
> various versions of CPython from PSF that include the corresponding 
> versions of IDLE, with its integrated shell and editor, but not the 3rd 
> party modules included with Anaconda.
> 
> If you are just starting with Python, and do not work somewhere that 
> uses 2.7, I would ignore 2.7.  Unless you absolutely need the 32 bit 
> version, I delete it.
> 
> > I'm having a problem using pip:
> > 1. Does one have to use pip in the commandline?
> 
> Yes, use command line programs in a command line console/window.
> 
> > Why can't I use pip while in IDLE
> 
> Would you expect to use pip in MS Excel?  If you type 'python' at a 
> command line, and get the '>>>' REPL prompt (google REPL), then your 
> input goes to the python interpreter, which only accepts python 
> statements.  The same is true in the IDLE Shell, and when you run python 
> code in the editor.
> 
> [Some 3rd party IDEs have a front end for PIP. I wanted to add this for 
> IDLE but the project was vetoed when partly done.]
> 
> > 2. For some unknown reason, I have "defaulted" to use IDLE python 3.6, 32 
> > bit version.
> 
> The order of installation, choices you made during installation, and how 
> you start python.  (With just one python installed, there would be no 
> problem.)  Read the first chapter of 
> https://docs.python.org/3/using/index.html and the chapter for your OS 
> (which you should have specified ;-)
> 
> -- 
> Terry Jan Reedy

Many thanks Terry. I'm back to the proverbial drawing board. On a side note, 
I'm uninstalling ANACONDA and re-installing. Seems like the whold 400mb of the 
win executable is missing a bunch of stuff.
-- 
https://mail.python.org/mailman/listinfo/python-list


pip and command line

2018-03-10 Thread GISDude
Hi all,
I'm hoping someone could help a wannabe python coder out. I'm an aspiring 
Data/AI/ML coder/programmer/datafiend - that might help with my situation.

In my various fits of python downloads, I've managed to download Anaconda, 
Pyscripter, IDLE(3.6/32 AND 64bit), IDLE 2.7. I'm thinking of PyCharm next... 
but that's another story.

I'm having a problem using pip:
1. Does one have to use pip in the commandline? Why can't I use pip while in 
IDLE or in my Anaconda distro?
2. For some unknown reason, I have "defaulted" to use IDLE python 3.6, 32 bit 
version. I would like to use some modules that are in the 64 bit(pyiso is 
one...don't ask it is a module for using DOE EIA data off their website) and 
the requests module is not in the 64 bit version, NOT my 32 bit version.

A) So...should I maybe uninstall my anaconda, pyscripter? Just use IDLE? 
B) Maybe change the envirionment variables to go between 3.6 32 bit and 3.6 64 
bit. Seems kinda lame to myself...

Thanks all and appreciate the feedback
R~
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: search cursor in pythonwin 2.1

2007-02-19 Thread GISDude
On Feb 18, 2:19 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Sun, 18 Feb 2007 13:12:20 -0300, GISDude [EMAIL PROTECTED]
 escribió:

  I am a GIS(geographic information systems) Analyst and in our
  software(ESRI ARCGIS 9.1) ESRI has implemented Python 2.1 as the
  scripting language of choice.

  In my script I'm going thru a dbf file and extracting NON-NULL values
  in a field. What I need to do with that is create a new dbf table with
  the values I found in it.

 I think you should either read the ArcGis documentation, or post your
 question in a specilized forum.
 Your problem is not about Python itself, but on how to use the
 esriGeoprocessing object.

  GP.Select_Analysis(neighborhoods.shp, neighborhoods_names.shp, '
  Names  \ null\ ')

 #at this point I'm stuck. how do I query out a NON-
  NULL value?
 #or a value in the Names field?

 As a side note, on a standard SQL database, the condition would read
 Names IS NOT NULL, but I don't know if this is applicable or not.

 --
 Gabriel Genellina

Gabriel,

Thanks for the reply. After looking at the docs again, you are correct
NAMES IS NOT NULL would be the correct syntax.

I thought it was NAMES  NULL

Thanks again

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


search cursor in pythonwin 2.1

2007-02-18 Thread GISDude
Hi all.
I am trying to create a little script(I think) that will basically use
a search cursor.

I am a GIS(geographic information systems) Analyst and in our
software(ESRI ARCGIS 9.1) ESRI has implemented Python 2.1 as the
scripting language of choice.

In my script I'm going thru a dbf file and extracting NON-NULL values
in a field. What I need to do with that is create a new dbf table with
the values I found in it.

Here is my sample code so far:
# This is a basic script for searching thru a table
# seeing if a field has a value, then writing that record
# to a brand new dbf
#
# Import basic modules
import win32com.client, sys, os, string


# Create the basic Geoprocessor Object
GP = win32com.client.Dispatch(esriGeoprocessing.GpDispatch.1)

# Make sure to setup proper licensce level from ESRI
GP.SetProduct(arcview)

# Set the input workspace - I WONT USE THE ARGUMENT DIALOG BOX
GP.Workspace = E:/IntermediateGISProgrammingGEOG376/labs/
neighborhoods



# THIS IS THE SPOT WHERE I'M MESSING UP
# I THINK AT THIS POINT I NEED TO:
# 1: OPEN THE SHAPEFILE
# 2: INITIALIZE THE FC VARIABLE
# 3: USE THE SEARCHCURSOR TO FIND THE RECORDS THAT HAVE A VALUE IN THE
NAME FIELD




# I looked in the Select Help file and a number of items popped up.
# However, I opened up Select - analysis and it shows how to select
# from a shapefile. I assume this is what I need?
GP.Select_Analysis(neighborhoods.shp, neighborhoods_names.shp, '
Names  \ null\ ')

   #at this point I'm stuck. how do I query out a NON-
NULL value?
   #or a value in the Names field?

Could anyone throw me a bone over here?

TIA

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


PY Zip

2007-01-30 Thread GISDude
Hi all.

I am trying to find a module that has a Zip utility that I can use in
Python. I would like to be able to call the module and ZIP up a
directory. I thought there was such a module, but I have not been able
to find it.

I need this to be able to be used in Python Win. Is there a ZIP utilty
already stored with a basic PYTHON download?

Thanks all.

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


Re: Converting Microsoft Works databases.... *shudder*

2006-11-03 Thread GISDude
Mike,
I totally forgot that MS Works was out there. Haven't used that one in
about 6 or 7 years. Honestly, your best bet is to convert to .csv or
some delimited .txt file. Once that is done, all your rows/columns will
be nice and neat .
Once that is done, (and since your client doesn't have ACCESS, try
MYSQL or POSTGRESQL(they are open source). They can handle A LOT OF
DATA, so however big your orginal DB is, you can import it to one of
these more than capable OS freebie Databases.

Good luck
Michael B. Trausch wrote:
 I was wondering if anyone has had any experience with this.  Someone I
 know is trying to move away from Microsoft Works, and I am trying to
 look into a solution that would convert their data in a lossless fashion
 to a more modern format.  The database has more than 65K rows, so
 converting it to be an Excel spreadsheet, would, AFAIK, not be an option.

 It would seem that MS Works can export the database as a DBF format
 database, though I have not tried it.  Before I get started, I was
 wondering if anyone has been through this problem in the past and used
 Python to solve the problem.  Knowing nearly nothing about the DBase
 family of application software, and database formats, I find myself
 feeling like the information out there is, frankly, a bit overwhelming.

 Would the recipe specified in the dbf to csv thread be useful here for
 a file in DBase IV format?  It of course uses the same extension, but I
 am not sure if the file semantics are at all similar.  The idea at the
 end would be to probably create a database on an small SQL server (like
 MySQL) and let the person access their data using ODBC on their Windows
 workstation so that they can create form letters and the like.  They do
 not have access to MS Office's Access product, nor do they wish to use
 OOo Base (and I can't say that I blame them -- it seems to crash far too
 often to be considered reliable stuff).
 
   -- Mike

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


Re: New-style Python icons

2006-03-20 Thread GISDude
very sharp! i like 'em!

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


python and ARCView GIS desktop

2005-09-07 Thread GISDude
hi all. I am a newbie, so be kind.
I am using ARCView GIS 9.1 and python win. I am trying to develop a
module using the GZIP module in my ARCView map session. What I am
attempting to do (I think) is use the zip mod to zip up all the files
in a .mxd document into one neat little zipped file, ready to copy to
cd or email(if it's small enough(.

I got this idea while using autocad. There is a function in autocad
(E-TRANSMIT) that allows you to press the button on the toolbar and it
will zip up all files(and dependent files too) in the current drawing
and have it in one zip file ready for email.

I thought ESRI would think of this but when I've posted this to the
message boards, there is no response.

I was wondering if anyone had any ideas. Maybe I could use VBA or
something else?
Thanks in advance

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