I'm still new at this. I can't get this to work as a script. If I just
manually insert the values for sys.argv[1] and sys.argv[2] it works
fine, but I can't pass the variables from the command line. What am I
doing wrong? On windows xp, python 2.4.3
Thank you
import os
import fnmatch
import sys
def all_files(root, patterns='*', single_level=Fa lse,
yield_folders=F alse):
# Expand patterns from semicolon-separated string to list
patterns = patterns.split( ';')
for path, subdirs, files in os.walk(root):
if yield_folders:
files.extend(su bdirs)
files.sort()
for name in files:
for pattern in patterns:
if fnmatch.fnmatch (name, pattern):
yield os.path.join(pa th, name)
break
if single_level:
break
for path in all_files(sysar gv[1], sysargv[2]):
print path
ps - The original script is from the excellent Python Cookbook, but
obviously I'm breaking it by trying to pass arguments to it :) 12 4539
Em Dom, 2006-04-09 Ã*s 19:41 -0700, BartlebyScriven er escreveu: for path in all_files(sysar gv[1], sysargv[2]):
Instead of sysargv, use sys.argv.
--
Felipe.
Duh! Headsmack.
Thanks. But also, I discovered something else. If I name the script
findmyfiles.py and run it from the command line while in the directory
where it is stored (on windows), I must run it as:
findmyfiles.py d:/notes notes*.*
I was used to being able to run scripts by just typing the script name,
even without the .py extension, but
findmyfiles d:/notes notes*.* does not work
Thank you, Felipe
In article <11************ **********@i40g 2000cwc.googleg roups.com>,
"BartlebyScrive ner" <rp*******@gmai l.com> wrote: I was used to being able to run scripts by just typing the script name, even without the .py extension, but
findmyfiles d:/notes notes*.* does not work
The MS-DOS foundation on which Windows is built only supports a small
number of extensions for "executable " files (.COM, .EXE and .BAT), with
no provision for any extensions to these.
Lawrence D'Oliveiro enlightened us with: The MS-DOS foundation on which Windows is built only supports a small number of extensions for "executable " files (.COM, .EXE and .BAT), with no provision for any extensions to these.
Common misconception: screensavers are simply executable files with a
..scr extension. That's why they are often used to carry viruses.
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Lawrence D'Oliveiro wrote: In article <11************ **********@i40g 2000cwc.googleg roups.com>, "BartlebyScrive ner" <rp*******@gmai l.com> wrote:
I was used to being able to run scripts by just typing the script name, even without the .py extension, but
findmyfiles d:/notes notes*.* does not work
The MS-DOS foundation on which Windows is built only supports a small number of extensions for "executable " files (.COM, .EXE and .BAT), with no provision for any extensions to these.
That is wrong on so many levels:
Windows variants such as NT/2000/XP are not based on MS-DOS in any way.
The default set of "executable " file extensions recognised by Windows is:
.COM .EXE .BAT .CMD .VBS .VBE .JS .JSE .WSF .WSH
You can change the recognised extensions simply by setting the PATHEXT
environment variable.
>> That is wrong on so many levels
Including the level where I observed that I'd already been running
scripts without typing the .py extension for months, it's just that on
some scripts (seems to be the ones with functions defined in them) you
can't pass arguments unless you type the .py extension.
Anyway, thanks all.
rpd
BartlebyScriven er wrote: I'm still new at this. I can't get this to work as a script. If I just manually insert the values for sys.argv[1] and sys.argv[2] it works fine, but I can't pass the variables from the command line. What am I doing wrong? On windows xp, python 2.4.3
[... snip code ...]>
Did you see this thread a little while ago? http://groups.google.com/group/comp....d017deadbac420
In summary, it suggests looking at FTYPE and ASSOC,
and in particular at the %* param to FTYPE
The business of typing the .py or not is as secondary issue,
I suspect, and as someone else pointed out is governed by
the PATHEXT env var.
TJG
BartlebyScriven er wrote: That is wrong on so many levels
Including the level where I observed that I'd already been running scripts without typing the .py extension for months, it's just that on some scripts (seems to be the ones with functions defined in them) you can't pass arguments unless you type the .py extension.
There is a problem (which I think is finally fixed in XP) where you
couldn't redirect I/O when running Python scripts via PATHEXT, but that
doesn't sound like your problem.
Defining functions, or not, doesn't sound like it should affect the
arguments, except maybe if making your script longer had an effect, but I
have no problems running a long script with arguments.
What does the command "ftype Python.File" print on your system? If it is
wrong that could easily stop arguments being passed to scripts run by
entering the script name, but it ought to break them all whether or not you
type the extension explicitly.
The only other thing I can think is that you might already have a
findmyfiles.bat (or cmd/com/exe etc.) which is the one being picked up in
place of the Python script when you don't specify an extension. That could
certainly explain the behaviour.
Tim,
I had not seen the thread you linked to. I learned something, but it
still doesn't explain whatever is happening on my machine. When I run
assoc and ftype I get exactly the results you say I need to run the
scripts properly. However, this simple script (printargs.py) seems to
work whether I type the .py extention or not.
import os
import sys
print sys.argv
print sys.argv[0]
print sys.argv[1]
print sys.argv[2]
Whereas this more complex script (cbfindfiles.py ) will NOT work unless
I type the .py extension. Otherwise the arguments don't seem to pass.
import os
import fnmatch
import sys
def all_files(root, patterns='*', single_level=Fa lse,
yield_folders=F alse):
"""walks the directory tree starting at root and finds all files
matching patterns"""
# Expand patterns from semicolon-separated string to list
patterns = patterns.split( ';')
for path, subdirs, files in os.walk(root):
if yield_folders:
files.extend(su bdirs)
files.sort()
for name in files:
for pattern in patterns:
if fnmatch.fnmatch (name, pattern):
yield os.path.join(pa th, name)
break
if single_level:
break
if __name__ == "__main__":
for path in all_files(sys.a rgv[1], sys.argv[2]):
print path
It's not big deal. I don't mind typing the .py extension. It's just a
curious quirk. Thanks for your help.
Rick This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: grumfish |
last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code:
connection = MySQLdb.connect(host="localhost", user="root", passwd="pw",
db="japanese")
cursor = connection.cursor()
cursor.execute("INSERT INTO edict (kanji, kana, meaning) VALUES (%s, %s,
%s)", ("a", "b", "c") )
connection.close()
After running, a SELECT * on the table shows no new rows added. Adding
|
by: Christopher Jedlicka |
last post by:
I am trying to write a script that will access files on another
computer on the network but in a seperate domain. In order to access
the files, I need to first authenticate to the other domain as a
different user.
When I access files on another domain via explorer, it prompts for a
username/password. Is there some way I can pass this same information
through scripting to access a computer in the other domain?
I attempted to do this...
|
by: Robert |
last post by:
when using the following function to create a pass through query is there a
way to set the query property, "Returns Rows" to no. The default is yes.
Since we are planning to create the pass through with new parameters in the
where clause we need to set it each time. Thanx in advnance.
Function CreateSPT(SPTQueryName As String, strSQL As String)
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
|
by: Tim |
last post by:
Hi,
I am trying to pass a SQL Command, complete with parameters and their values
from one form to a modal form.
The modal form has;
public void GridDataPreload(System.Data.SqlClient.SqlCommand cmdPreload)
{
}
|
by: KFactor |
last post by:
Is it possible to pass form variables to a page on another server using
response.redirect?
Or is there a secure way of passing sensitive information from one site to
another such as a userID?
I would like to avoid using the querystring.
This is what I would like to do:
When a user clicks on the link, I need to add them to the database and then
| |
by: Joseph Lu |
last post by:
Hi, all
I have a stored procedure created in SQL Server like the following
lines.
// stored proceudre code starts here
CREATE PROCEDURE sp_insertdata
@strdata varchar(250) ,
@rsult BIT OUTPUT ,
@erridx CHAR(7) OUTPUT
|
by: Mayhem05 |
last post by:
I have an Access 2003 database that I need to write some VBA code for
to populate a table. The table is based on a query I have built in
Access queries. Right now I have 2 parameters that are passed to the
query from a form (DateFrom and DateTo). When I open the form and
populate the variables (DateFrom and DateTo) then open the query it
works fine.
My problem is that I need to do this from VBA coding and pass the 2
parameters to the...
|
by: techbuddha |
last post by:
Hi new to the forum and visual basic.
I am attempting to fix a migration of excel to access. The excel sheets where simple copied as is into access. for example one table lists the academic history from elementary to phd and on to post doctoral work alll on the same row. I want to break that up to have each level of education as a seperate record and then relate that back to the person.
i can pull the data into a recordset
I can...
|
by: sreedivya |
last post by:
Hi All
I am trying to create crystal reports. In this concern i have created a command which execute a stored procedure. This stored procedure takes three parameters which in turn i want to pass it from .aspx page. when i click on button parameters should pass to that stored procedure.
for example
exec sp_example @date='{?selecteddate}'
here date (varchar in stored procedure) and selected date (string type i selected) whenever i am...
|
by: Archanak |
last post by:
Hi,
I am using system command to call a program.
system("perl mail.cgi").
To this i want to pass an argument?
How do i pass an argument to system command?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |