473,385 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with first script please. files, directories, autocomplete

Hello everyone. Hopefully someone can point me in the right direction
here. I'm wanting to write a script to open microsoft word and adobe
pdf documents . Here is a little background:

At the company where I work (an inspection firm) all reports of
inspections are saved as word files. A particular file may contain many
reports named like this; 12345A-F.doc. This file contains six reports.
Most inspections also require a technique which is saved as a pdf. The
pdf filename is the identification of the part being inspected.

My command line script will work like this: The user is asked whether
they are searching for a technique or a report
Find (c)ertificate or (t)echnique
if they press 'c' they are then asked to enter certificate number.
Using the code below, no enter is needed

import msvcrt
print "Find (t)echnique or (c)ertificate: "
ch = msvcrt.getch()
if ch == 't':
print "Enter technique number: "
elif ch == 'c':
print "Enter certificate number: "
else:
print 'command not understood.'
raw_input()

Obviously I will need to wrap this into a function. What I need to know
how to do is save the two directories where the files are stored. if
'c' is selected I want to use that as the directory to search. same for
techniques. What is the best way to do this? I would also like to have
the text autocomplete after maybe three characters, is this possible?
Am I correct in thinking all files would have to be stored in a list
for this to work?

As you can tell I am new to programming. I don't want someone to write
this script for me, just give me some pointers to get going (maybe a
tutorial on the net). Unless someone really wants to write it of
course!

Many thanks and sorry for the long post.

Oct 7 '06 #1
3 1448
Forgot to mention I'm using python 2.5 on windows xp.

Oct 7 '06 #2

si***********@fastmail.co.uk wrote:
Hello everyone. Hopefully someone can point me in the right direction
here. I'm wanting to write a script to open microsoft word and adobe
pdf documents . Here is a little background:

At the company where I work (an inspection firm) all reports of
inspections are saved as word files. A particular file may contain many
reports named like this; 12345A-F.doc. This file contains six reports.
Most inspections also require a technique which is saved as a pdf. The
pdf filename is the identification of the part being inspected.

My command line script will work like this: The user is asked whether
they are searching for a technique or a report
Find (c)ertificate or (t)echnique

if they press 'c' they are then asked to enter certificate number.
Using the code below, no enter is needed

import msvcrt
print "Find (t)echnique or (c)ertificate: "
ch = msvcrt.getch()
if ch == 't':
print "Enter technique number: "
elif ch == 'c':
print "Enter certificate number: "
else:
print 'command not understood.'
raw_input()

Obviously I will need to wrap this into a function. What I need to know
how to do is save the two directories where the files are stored. if
'c' is selected I want to use that as the directory to search. same for
techniques. What is the best way to do this? I would also like to have
the text autocomplete after maybe three characters, is this possible?
Am I correct in thinking all files would have to be stored in a list
for this to work?

As you can tell I am new to programming. I don't want someone to write
this script for me, just give me some pointers to get going (maybe a
tutorial on the net). Unless someone really wants to write it of
course!

Many thanks and sorry for the long post.
You can store the dir name as a variable:
>>d = 'c:\home'
from os import *
listdir(d)
['.Config.pm.swp', '.run.bat.swp', 'AHK scripts', 'Archive',
'Config.pm', 'Docs', 'Images', 'Links', 'Music', 'Projects', 'Python
programs', 'run.bat', 'Share', 'Torrent']

As you see files are already in a list if you use listdir function.

You can autocomplete by getting each character, running through the
list and comparing using startswith() function:
>>l = listdir(d)
m = [m for m in l if m.startswith('A')]
m
['AHK scripts', 'Archive']

Then you can check how many matches you got. If you get one, print it
and ask for Enter to finalize the choice.

You might want to read tutorial on python.org. You also might want to
buy a python book, or read any number of other tutorials online if you
don't want to spend money right now. Your questions are kind of basic,
I don't want to discourage you but as you go along you will run into
many other things and it's not practical to ask every time and wait for
the answer (although people here are glad to help).

-Rainy

Oct 7 '06 #3
At Saturday 7/10/2006 16:34, Rainy wrote:
>You can store the dir name as a variable:
>d = 'c:\home'
from os import *
listdir(d)
['.Config.pm.swp', '.run.bat.swp', 'AHK scripts', 'Archive',
'Config.pm', 'Docs', 'Images', 'Links', 'Music', 'Projects', 'Python
programs', 'run.bat', 'Share', 'Torrent']
Note that \ is a escape character, and works fine in this case only
because \h is not a valid sequence.
Use instead 'c:\\home' or r'c:\home' or 'c:/home' (forward slashes
are fine in Windows too)

from ... import * is not the recommended way; use instead:

from os import listdir
listdir(d)

or

import os
os.listdir(d)

--
Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Oct 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
9
by: bhumikas | last post by:
Hi all, I need a help in perl script.The basic idea is,it must have command line arguments for the user flexibility.the files are in the format as shown below. MainFolder Directory ...
2
by: Justin09 | last post by:
Hello. I have a frames page that has a header, body and a footer. The header frame has an ajax autocomplete that returns a number and a string from a database. Here is what happens. The user...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.