3

I am having trouble setting up my project skeleton because now the guide is asking me to use Linux only commands and I'm on Windows. This entire guide up until this project has had no compatibility issues with Windows until a line of code in exercise 46.

I was able to do this:

$ mkdir -p projects
$ cd projects/
$ mkdir skeleton
$ cd skeleton
$ mkdir bin NAME tests docs

I was not able to do this:

$ touch NAME/__init__.py
$ touch tests/__init__.py

('touch' is not recognized as an internal or external command, operable program or batch file.)

I understand this isn't even the hard part of this exercise but the author doesn't provide any words at all about 'touch' or that he is suddenly using Linux.

jecaklafa
  • 109
  • 1
  • 2
  • 5
  • 3
    You should post a comment directly on the exercise page (http://learnpythonthehardway.org/book/ex46.html in case you're using a PDF or something) mentioning that you've had trouble. Zed Shaw, the author, personally responds to comments. I'm sure he'd like to know that this part of the book is confusing/doesn't work for Windows users. – Mitch Lindgren Jan 30 '12 at 19:26

6 Answers6

8

To touch a file is to simply create an empty file with that name. Use notepad and save a file with the name with no contents in it, making sure that you are in the proper directory.

For an answer to why would you want the __init__.py file in the first place, see this question.

Community
  • 1
  • 1
Hooked
  • 84,485
  • 43
  • 192
  • 261
5
> touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

I recommend you get hold of GnuWin32, the GNU tools compiled for Windows, and then you can use the same commands as your guide. Running Windows does not mean you cannot also use the command line like a *nix user.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
2

Touch just creates a new empty text file with the name you specify. I'm a linux guy but i might try this if I wanted a Windows command-line option.

You could always just right click in explorer to create a new text document. Or save an empty text file in notepad.

ben author
  • 2,855
  • 2
  • 25
  • 43
2

I would recommend skimming through Zed Shaw's Learn the CLI the Hard Way, which provides his recommended way of interacting with the command-line for your platform.

In the case of Windows, he recommends you use Powershell, which has the New-Item command:

> cd temp
> New-Item iamcool.txt -type file
> ls


      Directory: C:\Users\zed\temp


  Mode                LastWriteTime     Length Name 
  ----                -------------     ------ ---- 
  d----        12/17/2011   9:03 AM            iamcool.txt
davidtbernal
  • 13,434
  • 9
  • 44
  • 60
  • Given that this particular guide seems Unixy, Powershell is about as far from that paradigm as I can imagine. Powershell is nifty and all, but hardly likely to be what jecaklafa needs. – David Heffernan Jan 30 '12 at 20:07
  • 2
    The guide I linked to is by the same guy who wrote the guide the poster is using, and is in fact linked to at the beginning of [LPTHW](http://learnpythonthehardway.org/book/ex0.html#exercise-0-the-setup). – davidtbernal Jan 31 '12 at 05:13
1

To touch files that don't exist in windows you can also just redirect a no op to a file. Note do not do this on an existing file as it will overwrite it!

In your case this would be:

: > NAME/__init__.py
: > tests/__init__.py
Andrew Cox
  • 10,672
  • 3
  • 33
  • 38
1

I recommend cygwin. It has all unix command line tools like bash-shell, touch, cat, sed, awk,... Since the DOS-box is not nice, I recommend to install rxvt. It is like a xterm on unix/linux.

guettli
  • 25,042
  • 81
  • 346
  • 663