473,770 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1469
Forgot to mention I'm using python 2.5 on windows xp.

Oct 7 '06 #2

si***********@f astmail.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
3001
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 <<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>> <html>
8
5481
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
7
5387
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 from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
1
3721
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
5
3698
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 for repeated html im using the external js, i mean the TOP, BOTTOM they are repeated in every page, so i include them as functions in the external js and call them. Why it doesn't work?
1
4953
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: http://munich.schwarz-interactive.de/autocomplete.aspx
12
3016
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 the instructions and couldnt get the correct results. heres the code stuff... temperature=input("what is the temperature of the spam?") if temperature>50: print "the salad is properly cooked." else:
9
2415
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 Sub_directory files Sub_directory files Directory
2
1537
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 looks up a client in the autocomplete textbox. The ajax autocomplete give the user choices. the user selects the one he wants with either his mouse or the arrow keys and then presses ENT. THERE IS NO SUBMIT BUTTON. The value that was returned by...
1
10038
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,...
0
9906
tracyyun
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...
1
7456
isladogs
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...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.