Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106317 > unrolled thread
| Started by | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| First post | 2016-04-02 14:59 -0700 |
| Last post | 2016-04-03 07:45 -0700 |
| Articles | 20 on this page of 30 — 8 participants |
Back to article view | Back to comp.lang.python
[Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-02 14:59 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong BartC <bc@freeuk.com> - 2016-04-02 23:08 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Ned Batchelder <ned@nedbatchelder.com> - 2016-04-02 15:16 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong BartC <bc@freeuk.com> - 2016-04-02 23:27 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-02 15:31 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong BartC <bc@freeuk.com> - 2016-04-03 01:12 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-03 01:38 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 12:52 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 07:41 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong BartC <bc@freeuk.com> - 2016-04-03 16:11 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Rustom Mody <rustompmody@gmail.com> - 2016-04-03 08:25 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong BartC <bc@freeuk.com> - 2016-04-03 17:04 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 12:31 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 12:36 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Michael Selik <michael.selik@gmail.com> - 2016-04-03 19:46 +0000
Re: [Beginner] - Hanging in the code, can't figure out what's wrong BartC <bc@freeuk.com> - 2016-04-03 21:21 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 14:07 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Erik <python@lucidity.plus.com> - 2016-04-03 20:46 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 12:54 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Erik <python@lucidity.plus.com> - 2016-04-03 21:15 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 13:25 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Erik <python@lucidity.plus.com> - 2016-04-03 22:26 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 14:49 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Erik <python@lucidity.plus.com> - 2016-04-03 23:07 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Ben Finney <ben+python@benfinney.id.au> - 2016-04-05 06:49 +1000
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Michael Selik <michael.selik@gmail.com> - 2016-04-02 22:37 +0000
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-03 01:11 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-02 15:23 -0700
Re: [Beginner] - Hanging in the code, can't figure out what's wrong Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-03 01:08 +0100
Re: [Beginner] - Hanging in the code, can't figure out what's wrong "Loop.IO" <thisisink01@gmail.com> - 2016-04-03 07:45 -0700
Page 1 of 2 [1] 2 Next page →
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-02 14:59 -0700 |
| Subject | [Beginner] - Hanging in the code, can't figure out what's wrong |
| Message-ID | <66afb6f1-ca2b-4f9b-a1ec-ed255fa3030f@googlegroups.com> |
Hey
So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong?
If I press return it makes the batch file, otherwise it just hangs.
CODE:
import os
from os.path import join
lookfor = "iexplore.exe"
for root, dirs, files in os.walk('C:\\Program Files\\Internet Explorer'):
print "searching", root
if lookfor in files:
print "found: %s" % join(root, lookfor)
import sys
def create():
print("creating new file")
name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
try:
file=open(name,'w')
file.close()
except:
print("error occured")
sys.exit(0)
create()
[toc] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-04-02 23:08 +0100 |
| Message-ID | <ndpfno$fdh$1@dont-email.me> |
| In reply to | #106317 |
On 02/04/2016 22:59, Loop.IO wrote:
> Hey
>
> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong?
>
> If I press return it makes the batch file, otherwise it just hangs.
> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
You're asking for a file name to be entered. So that if ABC is pressed,
followed by Enter, it will use:
C:\Documents\PythonCoding\ABClaunch2.bat
Assuming that's the intention, then Enter is needed so that it knows
when the user has completed typing the name. If not, then just use:
name='C:\\Documents\\PythonCoding\\launch2.bat'
(If you want a single character name, without pressing Enter, that's
harder to do. Someone else will have to help.)
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2016-04-02 15:16 -0700 |
| Message-ID | <e2cbbcf8-86f4-4c14-989e-1d8046d4215c@googlegroups.com> |
| In reply to | #106319 |
On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote:
> On 02/04/2016 22:59, Loop.IO wrote:
> > Hey
> >
> > So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong?
> >
> > If I press return it makes the batch file, otherwise it just hangs.
>
> > name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
>
> You're asking for a file name to be entered. So that if ABC is pressed,
> followed by Enter, it will use:
>
> C:\Documents\PythonCoding\ABClaunch2.bat
That line of code will prompt the user:
C:\Documents\PythonCoding\
then the user enters ABC<enter>:
C:\Documents\PythonCoding\ABC
and raw_input returns "ABC", so name becomes "ABClaunch2.bat".
Presumably the intention here was to use the prompt as a suggestion
for a value to enter, but I can't be sure.
--Ned.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-04-02 23:27 +0100 |
| Message-ID | <ndpgql$im4$1@dont-email.me> |
| In reply to | #106320 |
On 02/04/2016 23:16, Ned Batchelder wrote:
> On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote:
>> On 02/04/2016 22:59, Loop.IO wrote:
>>> Hey
>>>
>>> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong?
>>>
>>> If I press return it makes the batch file, otherwise it just hangs.
>>
>>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
>>
>> You're asking for a file name to be entered. So that if ABC is pressed,
>> followed by Enter, it will use:
>>
>> C:\Documents\PythonCoding\ABClaunch2.bat
>
> That line of code will prompt the user:
>
> C:\Documents\PythonCoding\
>
> then the user enters ABC<enter>:
>
> C:\Documents\PythonCoding\ABC
>
> and raw_input returns "ABC", so name becomes "ABClaunch2.bat".
Yes, of course. I ran the code and picked up the wrong line even though
I printed out 'name'!
But, it does look as though that path is supposed to form part of the
resulting filename.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-02 15:31 -0700 |
| Message-ID | <03c7da56-c752-460f-98b1-84b7166a2cc3@googlegroups.com> |
| In reply to | #106322 |
On Saturday, April 2, 2016 at 11:27:49 PM UTC+1, BartC wrote:
> On 02/04/2016 23:16, Ned Batchelder wrote:
> > On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote:
> >> On 02/04/2016 22:59, Loop.IO wrote:
> >>> Hey
> >>>
> >>> So I built a keylogger using python as a test, got the code from the tutorial online, I want to improve on it to make it more automated, but the issue I'm having is it won't create the file until I press return, any clues where I'm going wrong?
> >>>
> >>> If I press return it makes the batch file, otherwise it just hangs.
> >>
> >>> name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
> >>
> >> You're asking for a file name to be entered. So that if ABC is pressed,
> >> followed by Enter, it will use:
> >>
> >> C:\Documents\PythonCoding\ABClaunch2.bat
> >
> > That line of code will prompt the user:
> >
> > C:\Documents\PythonCoding\
> >
> > then the user enters ABC<enter>:
> >
> > C:\Documents\PythonCoding\ABC
> >
> > and raw_input returns "ABC", so name becomes "ABClaunch2.bat".
>
> Yes, of course. I ran the code and picked up the wrong line even though
> I printed out 'name'!
>
> But, it does look as though that path is supposed to form part of the
> resulting filename.
>
> --
> Bartc
Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt?
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-04-03 01:12 +0100 |
| Message-ID | <ndpmuo$4sq$1@dont-email.me> |
| In reply to | #106323 |
On 02/04/2016 23:31, Loop.IO wrote:
> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt?
If you don't want the user to enter anything, then I explained how
before, just use:
name='C:\\Documents\\PythonCoding\\launch2.bat'
if that's the file name you need.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2016-04-03 01:38 +0100 |
| Message-ID | <mailman.386.1459643915.28225.python-list@python.org> |
| In reply to | #106331 |
On 03/04/2016 01:12, BartC wrote: > On 02/04/2016 23:31, Loop.IO wrote: > >> Oh i see, so the code prompts for a name.. so i'm more lost than i >> thought, what do I need to change to make it just create the file with >> the chosen name Launch2.bat without the prompt? > > If you don't want the user to enter anything, then I explained how > before, just use: > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > if that's the file name you need. > name = r'C:\Documents\PythonCoding\launch2.bat' Alternatively you could just use a forward slash. I'm not sure which is the most efficient, I'll leave that to others to test. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-03 12:52 -0700 |
| Message-ID | <bb071df3-beed-43d3-9c2a-1643c2892c42@googlegroups.com> |
| In reply to | #106334 |
On Sunday, April 3, 2016 at 1:38:48 AM UTC+1, Mark Lawrence wrote: > On 03/04/2016 01:12, BartC wrote: > > On 02/04/2016 23:31, Loop.IO wrote: > > > >> Oh i see, so the code prompts for a name.. so i'm more lost than i > >> thought, what do I need to change to make it just create the file with > >> the chosen name Launch2.bat without the prompt? > > > > If you don't want the user to enter anything, then I explained how > > before, just use: > > > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > > > if that's the file name you need. > > > > name = r'C:\Documents\PythonCoding\launch2.bat' > > Alternatively you could just use a forward slash. > > I'm not sure which is the most efficient, I'll leave that to others to test. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Hey Mark, Sorry i totally missed your input, and guess what, it solved it !!! Thanks man, it created the file and finished, what is different with r and raw_input
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-03 07:41 -0700 |
| Message-ID | <32c7ba6b-b61d-45fb-89a8-dd62aa09fe78@googlegroups.com> |
| In reply to | #106331 |
On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote: > On 02/04/2016 23:31, Loop.IO wrote: > > > Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt? > > If you don't want the user to enter anything, then I explained how > before, just use: > > name='C:\\Documents\\PythonCoding\\launch2.bat' > > if that's the file name you need. > > -- > Bartc Hi Bartc, i tried that, didn't work
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-04-03 16:11 +0100 |
| Message-ID | <ndrbl5$u2r$1@dont-email.me> |
| In reply to | #106361 |
On 03/04/2016 15:41, Loop.IO wrote:
> On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
>> On 02/04/2016 23:31, Loop.IO wrote:
>>
>>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt?
>>
>> If you don't want the user to enter anything, then I explained how
>> before, just use:
>>
>> name='C:\\Documents\\PythonCoding\\launch2.bat'
>>
>> if that's the file name you need.
>>
>> --
>> Bartc
>
> Hi Bartc, i tried that, didn't work
You mean it gave an error when you tried to create that file?
Does that path already exist on your machine? If not then trying to
create a file in a non-existent path won't work.
You can create the path manually outside of Python. Or look up the docs
to find out how to do that. A quick google suggested using os.makedirs
(to create multiple nested paths at the same time).
The following code worked on my machine:
import sys
import os
def create():
print("creating new file")
path="c:/Documents/PythonCoding/"
name=path+"launch2.bat"
try:
os.stat(path)
except:
os.makedirs(path)
print (name)
try:
file=open(name,'w')
file.close()
except:
print("error occured")
sys.exit(0)
create()
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2016-04-03 08:25 -0700 |
| Message-ID | <3596709a-c16d-401f-8ab3-70d0ab9dd9be@googlegroups.com> |
| In reply to | #106364 |
On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote:
> On 03/04/2016 15:41, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> >> On 02/04/2016 23:31, Loop.IO wrote:
> >>
> >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt?
> >>
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >> name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
>
> You mean it gave an error when you tried to create that file?
>
> Does that path already exist on your machine? If not then trying to
> create a file in a non-existent path won't work.
>
> You can create the path manually outside of Python. Or look up the docs
> to find out how to do that. A quick google suggested using os.makedirs
> (to create multiple nested paths at the same time).
>
> The following code worked on my machine:
>
> import sys
> import os
>
> def create():
> print("creating new file")
>
> path="c:/Documents/PythonCoding/"
> name=path+"launch2.bat"
>
> try:
> os.stat(path)
> except:
> os.makedirs(path)
>
> print (name)
>
> try:
> file=open(name,'w')
> file.close()
> except:
If you dont want the vigilantes out in their squadrons please dont do it that way.
More seriously you can do what you like but dont teach beginners to use bare excepts.
Do
except IOError # I think... else whatever is the error you want to trap
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-04-03 17:04 +0100 |
| Message-ID | <ndreo4$9l6$1@dont-email.me> |
| In reply to | #106365 |
On 03/04/2016 16:25, Rustom Mody wrote: > On Sunday, April 3, 2016 at 8:41:49 PM UTC+5:30, BartC wrote: >> You can create the path manually outside of Python. Or look up the docs >> to find out how to do that. A quick google suggested using os.makedirs >> (to create multiple nested paths at the same time). >> try: >> os.stat(path) >> except: >> os.makedirs(path) >> >> print (name) >> >> try: >> file=open(name,'w') >> file.close() >> except: > > If you dont want the vigilantes out in their squadrons please dont do it that way. > > More seriously you can do what you like but dont teach beginners to use bare excepts. They're not mine (the first is from the first google hit, the second is the OP's); if it was my choice I wouldn't use exceptions at all. But the primary issue here is that file not being created. Once the code works, it can be tweaked later and, if the path still needs creating from the code, there are doubtless better ways of doing it, with or without exceptions. At the minute we don't even know if this was the problem. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-03 12:31 -0700 |
| Message-ID | <860f0703-08a1-4721-86c9-67ddc129cdc6@googlegroups.com> |
| In reply to | #106364 |
On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> On 03/04/2016 15:41, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> >> On 02/04/2016 23:31, Loop.IO wrote:
> >>
> >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt?
> >>
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >> name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
>
> You mean it gave an error when you tried to create that file?
>
> Does that path already exist on your machine? If not then trying to
> create a file in a non-existent path won't work.
>
> You can create the path manually outside of Python. Or look up the docs
> to find out how to do that. A quick google suggested using os.makedirs
> (to create multiple nested paths at the same time).
>
> The following code worked on my machine:
>
> import sys
> import os
>
> def create():
> print("creating new file")
>
> path="c:/Documents/PythonCoding/"
> name=path+"launch2.bat"
>
> try:
> os.stat(path)
> except:
> os.makedirs(path)
>
> print (name)
>
> try:
> file=open(name,'w')
> file.close()
> except:
> print("error occured")
> sys.exit(0)
>
> create()
>
> --
> Bartc
The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one moment
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-03 12:36 -0700 |
| Message-ID | <99671ed7-7a89-4116-917d-3c9151847237@googlegroups.com> |
| In reply to | #106395 |
On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> > On 03/04/2016 15:41, Loop.IO wrote:
> > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> > >> On 02/04/2016 23:31, Loop.IO wrote:
> > >>
> > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i thought, what do I need to change to make it just create the file with the chosen name Launch2.bat without the prompt?
> > >>
> > >> If you don't want the user to enter anything, then I explained how
> > >> before, just use:
> > >>
> > >> name='C:\\Documents\\PythonCoding\\launch2.bat'
> > >>
> > >> if that's the file name you need.
> > >>
> > >> --
> > >> Bartc
> > >
> > > Hi Bartc, i tried that, didn't work
> >
> > You mean it gave an error when you tried to create that file?
> >
> > Does that path already exist on your machine? If not then trying to
> > create a file in a non-existent path won't work.
> >
> > You can create the path manually outside of Python. Or look up the docs
> > to find out how to do that. A quick google suggested using os.makedirs
> > (to create multiple nested paths at the same time).
> >
> > The following code worked on my machine:
> >
> > import sys
> > import os
> >
> > def create():
> > print("creating new file")
> >
> > path="c:/Documents/PythonCoding/"
> > name=path+"launch2.bat"
> >
> > try:
> > os.stat(path)
> > except:
> > os.makedirs(path)
> >
> > print (name)
> >
> > try:
> > file=open(name,'w')
> > file.close()
> > except:
> > print("error occured")
> > sys.exit(0)
> >
> > create()
> >
> > --
> > Bartc
>
> The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one moment
Ok the Bartc code gives me an error.
What is it that makes the code hang with what I have, you said it was that it's prompting for a name for the file, so how do I bypass that and force it to create the file with the name I've provided?
[toc] | [prev] | [next] | [standalone]
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Date | 2016-04-03 19:46 +0000 |
| Message-ID | <mailman.410.1459713208.28225.python-list@python.org> |
| In reply to | #106397 |
How do you know when you're done typing the name of the file?
It's hard to get tone right on the internet, so I'll clarify: this is not a
rhetorical question and I mean you, LoopIO, not a generic person.
On Sun, Apr 3, 2016, 8:40 PM Loop.IO <thisisink01@gmail.com> wrote:
> On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> > > On 03/04/2016 15:41, Loop.IO wrote:
> > > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> > > >> On 02/04/2016 23:31, Loop.IO wrote:
> > > >>
> > > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i
> thought, what do I need to change to make it just create the file with the
> chosen name Launch2.bat without the prompt?
> > > >>
> > > >> If you don't want the user to enter anything, then I explained how
> > > >> before, just use:
> > > >>
> > > >> name='C:\\Documents\\PythonCoding\\launch2.bat'
> > > >>
> > > >> if that's the file name you need.
> > > >>
> > > >> --
> > > >> Bartc
> > > >
> > > > Hi Bartc, i tried that, didn't work
> > >
> > > You mean it gave an error when you tried to create that file?
> > >
> > > Does that path already exist on your machine? If not then trying to
> > > create a file in a non-existent path won't work.
> > >
> > > You can create the path manually outside of Python. Or look up the docs
> > > to find out how to do that. A quick google suggested using os.makedirs
> > > (to create multiple nested paths at the same time).
> > >
> > > The following code worked on my machine:
> > >
> > > import sys
> > > import os
> > >
> > > def create():
> > > print("creating new file")
> > >
> > > path="c:/Documents/PythonCoding/"
> > > name=path+"launch2.bat"
> > >
> > > try:
> > > os.stat(path)
> > > except:
> > > os.makedirs(path)
> > >
> > > print (name)
> > >
> > > try:
> > > file=open(name,'w')
> > > file.close()
> > > except:
> > > print("error occured")
> > > sys.exit(0)
> > >
> > > create()
> > >
> > > --
> > > Bartc
> >
> > The issue is that it hangs, there is no error. its like it pauses until
> i press enter, ill try what you've posted one moment
>
> Ok the Bartc code gives me an error.
>
> What is it that makes the code hang with what I have, you said it was that
> it's prompting for a name for the file, so how do I bypass that and force
> it to create the file with the name I've provided?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2016-04-03 21:21 +0100 |
| Message-ID | <ndrtq8$657$1@dont-email.me> |
| In reply to | #106397 |
On 03/04/2016 20:36, Loop.IO wrote: > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote: >> The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one momen > Ok the Bartc code gives me an error. This is confusing! I know you said you fixed the problem now, but if it was waiting for the user to press enter, then you still had a raw_input or input() call in your code. You need to get rid of that raw_input(). That was explained early on in the thread but perhaps you didn't grasp that you had to use: name = '....' in place of: name = raw_input(....) and not as well as! (And the 'r' in name = r'....' isn't a different version of raw_input(), it's just a way of entering strings without having to type \\ when you need \.) -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-03 14:07 -0700 |
| Message-ID | <cc5edd4e-0b3c-4073-81aa-c760b5c5ea93@googlegroups.com> |
| In reply to | #106405 |
On Sunday, April 3, 2016 at 9:21:44 PM UTC+1, BartC wrote: > On 03/04/2016 20:36, Loop.IO wrote: > > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote: > > >> The issue is that it hangs, there is no error. its like it pauses until i press enter, ill try what you've posted one momen > > > > Ok the Bartc code gives me an error. > > This is confusing! I know you said you fixed the problem now, but if it > was waiting for the user to press enter, then you still had a raw_input > or input() call in your code. > > You need to get rid of that raw_input(). That was explained early on in > the thread but perhaps you didn't grasp that you had to use: > > name = '....' > > in place of: > > name = raw_input(....) > > and not as well as! > > (And the 'r' in name = r'....' isn't a different version of raw_input(), > it's just a way of entering strings without having to type \\ when you > need \.) > > -- > Bartc Hey Bartc I'm sorry about getting you confused, I did try that, but it didn't work, maybe it was me, but now I've tried it again it does work. I've now managed to get the file to be created and write to the file so its all working fine. The only question left is when I've conducted a search through all the drives for a browser .exe file, how do I take the search results and put them in to a text file, but I guess that's for another thread.
[toc] | [prev] | [next] | [standalone]
| From | Erik <python@lucidity.plus.com> |
|---|---|
| Date | 2016-04-03 20:46 +0100 |
| Message-ID | <mailman.409.1459712951.28225.python-list@python.org> |
| In reply to | #106361 |
Hi Loop.IO, On 03/04/16 15:41, Loop.IO wrote: >> If you don't want the user to enter anything, then I explained how >> before, just use: >> >> name='C:\\Documents\\PythonCoding\\launch2.bat' >> >> if that's the file name you need. >> >> -- >> Bartc > > Hi Bartc, i tried that, didn't work FYI, for the future. Telling someone what _didn't_ happen is generally not very useful to them if you expect them to try to help further. If you tell them what _did_ happen (be that an error message or a weird file created or a pain in your leg or whatever), then that is much more likely to be productive ;) If you would like someone to diagnose your illness, you must explain your symptoms ... E.
[toc] | [prev] | [next] | [standalone]
| From | "Loop.IO" <thisisink01@gmail.com> |
|---|---|
| Date | 2016-04-03 12:54 -0700 |
| Message-ID | <686d7aab-4020-4840-a1b7-fce8e89c6633@googlegroups.com> |
| In reply to | #106398 |
On Sunday, April 3, 2016 at 8:49:28 PM UTC+1, Erik wrote: > Hi Loop.IO, > > On 03/04/16 15:41, Loop.IO wrote: > >> If you don't want the user to enter anything, then I explained how > >> before, just use: > >> > >> name='C:\\Documents\\PythonCoding\\launch2.bat' > >> > >> if that's the file name you need. > >> > >> -- > >> Bartc > > > > Hi Bartc, i tried that, didn't work > > FYI, for the future. > > Telling someone what _didn't_ happen is generally not very useful to > them if you expect them to try to help further. > > If you tell them what _did_ happen (be that an error message or a weird > file created or a pain in your leg or whatever), then that is much more > likely to be productive ;) > > If you would like someone to diagnose your illness, you must explain > your symptoms ... > > E. The original post said what did happen, the code runs and hangs on the create file, and once i press Enter it then finishes and creates the file, not sure how you missed that but thanks
[toc] | [prev] | [next] | [standalone]
| From | Erik <python@lucidity.plus.com> |
|---|---|
| Date | 2016-04-03 21:15 +0100 |
| Message-ID | <mailman.412.1459714509.28225.python-list@python.org> |
| In reply to | #106401 |
On 03/04/16 20:54, Loop.IO wrote: > The original post said what did happen, the code runs and hangs on > the create file, and once i press Enter it then finishes and creates > the file, not sure how you missed that but thanks Yes, I read your original post. That was days ago. The comment I was replying to was you telling BartC that what he had suggested "didn't work" (with no further information). Please pay attention to the context of the email you are responding to. E.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.python
csiph-web