Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:file': 0.07; 'string': 0.09; 'excluding': 0.09; 'input,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'assume': 0.14; 'wrote': 0.14; '"\\n")': 0.16; '"w")': 0.16; 'filename.': 0.16; 'parameter.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; "where's": 0.16; 'files.': 0.16; 'trying': 0.19; 'command': 0.22; 'import': 0.22; 'specify': 0.24; 'file.': 0.24; "i've": 0.25; 'nearly': 0.26; 'order.': 0.26; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'words': 0.29; 'characters': 0.30; "i'm": 0.30; 'that.': 0.31; 'anyone': 0.31; 'file': 0.32; 'run': 0.32; 'another': 0.32; 'text': 0.33; 'could': 0.34; 'convert': 0.35; 'but': 0.35; 'version': 0.36; 'found.': 0.36; 'marks': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'files': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'remove': 0.60; 'read': 0.60; 'lower': 0.61; 'skip:o 30': 0.61; 'name:': 0.61; "you're": 0.61; "you've": 0.63; 'making': 0.63; 'email addr:gmail.com': 0.63; 'such': 0.63; 'more': 0.64; 'total': 0.65; 'finally': 0.65; 'anything.': 0.68; 'prompt': 0.68; 'safer': 0.84; 'subject:read': 0.84; 'subject::': 0.85; 'choice.': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:User prompt as file to read Date: Sat, 22 Mar 2014 10:34:25 -0400 (EDT) Organization: news.gmane.org References: <83317185-701d-4218-a748-00b75b51843c@googlegroups.com> X-Gmane-NNTP-Posting-Host: dpc6744198232.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395498592 news.xs4all.nl 2970 [2001:888:2000:d::a6]:52547 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68778 kjakupak@gmail.com Wrote in message: > I'm trying to create a program that will prompt the user for a list of text files to read from, then read those text files and build a dictionary of all the unique words found. Then finally put those unique words into another file and make it alphabetical order. Specify python version and os. I assume python 3 and Windows. > > What I've got: > > import string > > s = input("Enter a file name: ") + ".txt" > filepath = "I:\\" + s So you've got a filename. You're not using it for anything. Where's your open? Where's your read or readline? > > # remove all punctuation marks and make lower case > s_nopunct = "".join(c for c in s if c not in string.punctuation).lower() Are you sure you want a single string nearly the total size of your 3 files? Could be huge. Might be better to do it incrementally. It's a lot safer to include the characters you want, instead of excluding some of the ones you don't. And many valid words contain punctuation such as apostrophe. > > # convert to a sorted list of unique words via set comprehension > list_unique = sorted(list({word for word in s_nopunct.split()})) > > print("\nSorted list of unique words in sentence:") > print(list_unique) > > with open("C:\\Users\\Desktop\\words.dat", "w") as f: > for x in list_unique: > f.write(x + "\n") > > I need help making it so that the user is prompted to enter at least 3 files. Need a while loop for that. > And also, I tried making those unique words to write to another file (I got it that far), but how do I make it more of an arbitrary path (rather than the C:\Users etc) since I need it so that anyone can run that program and write/find to that file. > That could be another input, or it could be a command line parameter. Your choice. -- DaveA