Re: Question on how to open other programs and files (Alan Gauld) Sorry for being confusing on my last e-mail. I will try to clarify my intents a bit further. In short, I want to be able to read the data in the file as well as launch document viewer in Python. For one of the files I want to read the data from a Python script that's in the same folder as the GUI Python script. For the pdf file I simply want to be able to launch document viewer from Python. I know it is probably a lengthy and demanding request, but I just want to be able to do both eventually in my GUI program. I am still very new at Python, and so any help would be very useful for me. I have tried to look up different tutorials online, but I have not found one that addresses my issues.
On Sun, Feb 8, 2009 at 1:10 AM, <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Completed project. Is this correct? Can I simplify my > formulas? (cclpia...@comcast.net) > 2. Oops! I just corrected my file:RE Completed project is this > correct? (cclpia...@comcast.net) > 3. Question on how to open other programs and files (Hi) > 4. Re: Exec(uting) Code in a Dictionary? (spir) > 5. Re: Question on how to open other programs and files (Alan Gauld) > 6. Re: WINSOCK stdin question (Alan Gauld) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 7 Feb 2009 20:45:25 -0700 > From: cclpia...@comcast.net > Subject: [Tutor] Completed project. Is this correct? Can I simplify my > formulas? > To: tutor@python.org > Message-ID: <4070a0f9-63dc-4bbf-80fa-6d369b656...@comcast.net> > Content-Type: text/plain; charset="us-ascii"; Format="flowed"; > DelSp="yes" > > Hello, I've enclosed a completed project (my first!) and would like > to know of it's accuracy. Also, what I could do to simplify the > language. > > Thanks, > > Pat > > -------------- next part -------------- > A non-text attachment was scrubbed... > Name: Grant.py > Type: text/x-python-script > Size: 2935 bytes > Desc: not available > URL: < > http://mail.python.org/pipermail/tutor/attachments/20090207/940c1e50/attachment-0001.bin > > > > ------------------------------ > > Message: 2 > Date: Sat, 7 Feb 2009 21:02:21 -0700 > From: cclpia...@comcast.net > Subject: [Tutor] Oops! I just corrected my file:RE Completed project > is this correct? > To: tutor@python.org > Message-ID: <47b95607-d82c-4c70-b16b-d4be610bf...@comcast.net> > Content-Type: text/plain; charset="us-ascii"; Format="flowed" > > Forget the first, this is the corrected version. > > Thanks, > > Pat > -------------- next part -------------- > A non-text attachment was scrubbed... > Name: Grant.py > Type: text/x-python-script > Size: 2901 bytes > Desc: not available > URL: < > http://mail.python.org/pipermail/tutor/attachments/20090207/afc8b9e6/attachment-0001.bin > > > > ------------------------------ > > Message: 3 > Date: Sat, 7 Feb 2009 22:09:04 -0800 > From: Hi <haztan...@gmail.com> > Subject: [Tutor] Question on how to open other programs and files > To: tutor@python.org > Message-ID: > <ef0bf91e0902072209l31dd6027sb2ba0104a38c7...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > I have a question regarding how to open other programs and files in Python > code. I am creating a simple interface and I want it to be able to open > other files, such as a text file or a pdf file. However, those files are > usually associated with other programs - for instance, gedit for text and > document viewer for pdf (I am using Ubuntu 8.10). What syntax or commands > do > I need in order to do so. I've used os.popen in Windows XP and it works > fine, but the same code does not work in Ubuntu. This is the part of my > code > that deals with opening files/programs: > > def openfile(self, event): > result = os.popen("home/user/textfile.txt") > > In the terminal it simply says, sh: home/user/textfile.txt: not found. And > I > have already set permissions via chmod +x on the files of my choosing. Any > help would be greatly appreciated. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tutor/attachments/20090207/83a89869/attachment-0001.htm > > > > ------------------------------ > > Message: 4 > Date: Sun, 8 Feb 2009 09:56:03 +0100 > From: spir <denis.s...@free.fr> > Subject: Re: [Tutor] Exec(uting) Code in a Dictionary? > To: tutor@python.org > Message-ID: <20090208095603.70a1f...@o> > Content-Type: text/plain; charset=UTF-8 > > Le Sat, 07 Feb 2009 13:50:01 -0800, > Wayne Watson <sierra_mtnv...@sbcglobal.net> a ?crit : > > > That's something for me to ponder, setattr. I'd rather not go off and > pick up on something like ConfigParser at this stage. I'd like to keep this > code somewhat simple and easy to understand, but yet have some flexibility > for changes. > > Dicts are very handy because they are still starightforwardly usable when a > name/key is unknown at design time, in addition to the value: > > d["foo"] = val > d[name] = val > > A typical use is precisely reading data from a config file where both names > and values are data, meaning defined by the user. So that you cannot > directly store them in a custom config object writing: > > config.name = val > > Setattr addresses this need: > > setattr(config,name,val) > > So that finally using an object or a dict are more or less equivalent, > rather a programmer choice. > * dict is slightly easier > * object allows slightly lighter code (obj.name vs obj["name"]) and a > syntax better consistent with the rest of python > * additionnal data attibutes, custom behaviour > > Denis > > > ------ > la vida e estranya > > > ------------------------------ > > Message: 5 > Date: Sun, 8 Feb 2009 09:03:07 -0000 > From: "Alan Gauld" <alan.ga...@btinternet.com> > Subject: Re: [Tutor] Question on how to open other programs and files > To: tutor@python.org > Message-ID: <gmm74e$ca...@ger.gmane.org> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > "Hi" <haztan...@gmail.com> wrote > > >I have a question regarding how to open other programs and files in > >Python > > code. I am creating a simple interface and I want it to be able to > > open > > other files, such as a text file or a pdf file. > > OK, lets clarify something first. > When you say open do you mean you want to open the file in Python > such that you can read the data into your python program? Or do > you mean you want to open the file in the default application on > your computer. In other words for a pdf file do you want to read > the data in the file or do you want to launch Acrobat on the file? > > > usually associated with other programs - for instance, gedit for > > text and > > document viewer for pdf (I am using Ubuntu 8.10). What syntax or > > commands do > > I need in order to do so. > > The "official" approach to laumnching applications is to > use the subprocess module. This replaces several other > mechanisms which are now considred obsolete. > > > I've used os.popen in Windows XP and it works > > fine, but the same code does not work in Ubuntu. > > It should work but subprocess replaces popen. > > > def openfile(self, event): > > result = os.popen("home/user/textfile.txt") > > > > In the terminal it simply says, sh: home/user/textfile.txt: not > > found. > > I suspect your path is wrong. Notice you are not using > an absolute path but a relative path, so unless you have > a directory called home in your current directory it will fail. > > But this is not opening the text file this is trying to execute > the text file and that is unlikely to work on Ubuntu. (In Windows > it will launch the default app - probably Notepad) So back to > the original question: do you want to open the t5extfile in > Python or do you want to launch gedit from Python? > > Untiol you resolve that conundrum we can't really help > much more. > > HTH, > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > > > ------------------------------ > > Message: 6 > Date: Sun, 8 Feb 2009 09:08:09 -0000 > From: "Alan Gauld" <alan.ga...@btinternet.com> > Subject: Re: [Tutor] WINSOCK stdin question > To: tutor@python.org > Message-ID: <gmm7ds$cv...@ger.gmane.org> > Content-Type: text/plain; format=flowed; charset="utf-8"; > reply-type=original > > > Yes, this is exactly what I am looking to accomplish. > > On one host I have an application that is sending > > cmd.exe to a second host. > > OK, how is that application doing that? What port is > it sending the output to on the remote host? You say > CMD.exe but that is the windows shell. There is no > way to direct it to another host directly so how is > this application redirecting cmd.exe? Does it have > a name? > > You might need to write two programs, one on the > host computer to run and redirect cmd.exe to the > remote PC and then relay the returned data as > input to CMD.exe as well as another app on the > remote PC to pick up the incoming data and > relay the user input back down the socket. > > We need to know a lot more about how this thing > is glued together. > > Alan G. > > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 60, Issue 36 > ************************************* >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor