Thank you all for your help. 1) I need to list words with uppercase first, then those with lower case; I used istitle() and isupper (don't know the method for mixed case yet) 2) Steve, it's a compliment that you though I'd undersand your code, but I only know conditional statements, started on lists, not functions yet. nand is still Greek to me right now. 3) If someone input "Thank you my FOLKS, i want the output to print words with upper case first:
Thank FOLKS you my 3) Can someone help me make my code work in a very simple way. I am still learning, but watch this space colleagues; I may be helping you guys in a few months ;) Thanks to all who took their time to help. Future Python Expert, Cathy. My initial code: s=input("Write a sentence: ") list=s.strip().split() for word in list: list2 = (word.isupper() or word.istitle()) print (word) else print (word) On Wed, Jan 5, 2011 at 7:35 PM, <python-list-requ...@python.org> wrote: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-requ...@python.org > > You can reach the person managing the list at > python-list-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: Help with code-lists and strings (GrayShark) > 2. Help with a Python coding question (kanth...@woh.rr.com) > 3. Re: Help with a Python coding question (Emile van Sebille) > 4. Re: Help with a Python coding question (Justin Peel) > 5. Importing modules from miscellaneous folders (Jshgwave) > 6. Searching Python-list (Slie) > 7. Re: Interrput a thread (Adam Skutt) > > > ---------- Forwarded message ---------- > From: GrayShark <howe.ste...@gmail.com> > To: python-list@python.org > Date: Wed, 05 Jan 2011 16:56:40 -0600 > Subject: Re: Help with code-lists and strings > On Wed, 05 Jan 2011 14:58:05 -0500, Terry Reedy wrote: > > > On 1/5/2011 12:57 PM, Cathy James wrote: > > > >> I am learning python and came across an excercise where i need to use > >> lists to strip words from a sentence; starting with those containing > >> one or more uppercase letters, followed by words with lower case > >> letters. > > > > When writing code, it is good to start with one or more input-output > > pairs that constitute a test. For example, what, exactly, do you want to > > result from > > "Some special words are ALLCAPS, TitleCase, and MIXed." > > > > It is also good to think about all relevant cases. Note the following: > > >>> 'MIXed'.isupper() or 'MIXed'.istitle() > > False > > > > Do you want punctuation stripped off words? You might skip that at > > first. > > In python it's best to build up you functional needs. So two steps. First > a nand (negative 'and' operation). Then wrap that with a function to create > two strings of your list element, you''re calling 'word'. By the way, > list is reserved word, like string. Don't get in the bad habit of using it. > > def nand( a, b ): > """nand has to vars. Both must be strings """ > return( ( not eval( a ) ) and ( not eval( b ) ) ) > > Eval of 'Abcd'.isupper() returns False. Ditto 'Abcd'.islower(); negate both > results, 'and' values, return. > > Now wrap 'nand' in packaging an you're cooking with grease. > def mixed_case( str ): > return nand( "'%s'.islower()" % str , "'%s'.isupper()" % str ) > > or if that's too advanced/compact, try ... > def mixed_case( str ): > # nand() needs strings > a = "'%s'.isupper()" % str > b = "'%s'.islower()" % str > res = nand( a, b ) > return res > > >>> mixed_case('Abcd' ) > True > >>> mixed_case('ABCD' ) > False > >>> mixed_case('abcd' ) > False > > Good luck > Steven Howe > > > > ---------- Forwarded message ---------- > From: kanth...@woh.rr.com > To: python-list@python.org > Date: Wed, 05 Jan 2011 17:12:13 -0600 > Subject: Help with a Python coding question > I want to use Python to find all "\n" terminated > strings in a PDF file, ideally returning string > starting addresses. Anyone willing to help? > > > -- > --------------------------------- --- -- - > Posted with NewsLeecher v4.0 Final > Web @ http://www.newsleecher.com/?usenet > ------------------- ----- ---- -- - > > > > > ---------- Forwarded message ---------- > From: Emile van Sebille <em...@fenx.com> > To: python-list@python.org > Date: Wed, 05 Jan 2011 15:45:36 -0800 > Subject: Re: Help with a Python coding question > On 1/5/2011 3:12 PM kanth...@woh.rr.com said... > >> I want to use Python to find all "\n" terminated >> strings in a PDF file, ideally returning string >> starting addresses. Anyone willing to help? >> > > pdflines = open(r'c:\shared\python_book_01.pdf').readlines() > sps = [0] > for ii in pdflines: sps.append(sps[-1]+len(ii)) > > Emile > > > > > ---------- Forwarded message ---------- > From: Justin Peel <pee...@gmail.com> > To: python-list@python.org > Date: Wed, 5 Jan 2011 18:14:28 -0700 > Subject: Re: Help with a Python coding question > > > On Wed, Jan 5, 2011 at 4:45 PM, Emile van Sebille <em...@fenx.com> wrote: > >> On 1/5/2011 3:12 PM kanth...@woh.rr.com said... >> >> I want to use Python to find all "\n" terminated >>> strings in a PDF file, ideally returning string >>> starting addresses. Anyone willing to help? >>> >> >> pdflines = open(r'c:\shared\python_book_01.pdf').readlines() >> sps = [0] >> for ii in pdflines: sps.append(sps[-1]+len(ii)) >> >> Emile >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > Bear in mind that pdf files often have compressed objects in them. If that > is the case, then I would recommend opening the pdf in binary mode and > figuring out how to deflate the correct objects before doing any searching. > PyPDF is a package that might help with this though it could use some > updating. > > ---------- Forwarded message ---------- > From: Jshgwave <jshgw...@yahoo.com> > To: python-list@python.org > Date: Wed, 5 Jan 2011 17:08:14 -0800 (PST) > Subject: Importing modules from miscellaneous folders > On a Windows PC, I would like to be able to store modules in > topic-specific foldersinstead of in Python26/Lib/site-packages, > and then import into an IPython session those modules and the > functions in them. > > To test this, I have made a toy module: > > --- > > """ > toy_module.py > > This is for testing the importing of modules from folders > other than "Lib". > > The first statement below is from Langtangen, Primer, p.143. > At allows running the module as a program, as well as > importing it as a module. > """ > > > if __name__ == '__main__' : > > def double_it (a) : > b = 2.*a > print 'double_it in toy_module: a = ', a, ', b = ', b > return b > > > def triple_it (a) : > b = 3.*a > print 'triple_it in toy_module: a = ', a, ', b = ', b > return b > --- > > I have tried many ways of importing this module and its functions, but > all of them have failed. In the IPython session below, the failures > have been flagged for easy identification by "<<<". > > --- > > Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit > (Intel)] > Type "copyright", "credits" or "license" for more information. > > IPython 0.10.1 -- An enhanced Interactive Python. > ? -> Introduction and overview of IPython's features. > %quickref -> Quick reference. > help -> Python's own help system. > object? -> Details about 'object'. ?object also works, ?? prints more. > > In [1]: # Test importing from other than Lib. > > In [2]: # 2011-01-05 > > In [3]: function_dir = 'G:\\Python_2010-12\\JH_Python_Functions' > > In [4]: # That is for the PC at work. > > In [5]: import os > > In [6]: os.getcwd() > Out[6]: 'C:\\Documents and Settings\\Hornstein' > > In [7]: os.chdir(function_dir) > > In [8]: os.getcwd() > Out[8]: 'G:\\Python_2010-12\\JH_Python_Functions' > > In [9]: import toy_module > > In [10]: result1 = toy_module.double_it(3.) > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > > G:\Python_2010-12\JH_Python_Functions\<ipython console> in <module>() > > AttributeError: 'module' object has no attribute 'double_it' <<< 1 > > In [11]: from toy_module import double_it as twox > --------------------------------------------------------------------------- > ImportError Traceback (most recent call last) > > G:\Python_2010-12\JH_Python_Functions\<ipython console> in <module>() > > ImportError: cannot import name double_it <<< 2 > > In [12]: IsFileThere = os.isfile('toy_module.py') > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > > G:\Python_2010-12\JH_Python_Functions\<ipython console> in <module>() > > AttributeError: 'module' object has no attribute 'isfile' > > In [13]: IsFileThere = os.path.isfile('toy_module.py') > > In [14]: IsFileThere > Out[14]: True > > In [15]: filelist = os.listdir(function_dir) > > In [16]: filelist > Out[16]: > ['arc_to_-pitopi.py', > 'arc_to_0to2pi.py', > 'ClustersOfGalaxiesUtils.py', > 'ClustersOfGalaxiesUtils.py.txt', > 'ClustersOfGalaxiesUtils.Test.2010-08-04.1.txt', > 'CosmolFns.py.txt', > 'CosmolGeom_SmoothedMatter_CL.py.txt', > 'Distances_z.py.txt', > 'extract_text_line.py', > 'JH.PythonExperimentsOnWindows.2011-01-03.txt', > 'LAMBDA_calc.py', > 'loop_to_sum.example.py', > 'number_theory.py', > 'omega_plasma_radHz.py', > 'README.txt', > 'Sampletxt.IPython.txt', > 'Sampletxt.txt', > 'script2_1.py', > 'synchRadn.py.txt', > 'toy_module.py', > 'toy_module.pyc', > 'uv2D.Feb14-06.py <http://uv2d.feb14-06.py/>', > 'VariablesInFile.py', > 'VariablesInFile.pyc', > 'VLA_beamwidths.py', > 'z_cosmol.py'] > > In [17]: import glob > > In [18]: pyfilelist = glob.glob('*.py') > > In [19]: pyfilelist > Out[19]: > ['arc_to_-pitopi.py', > 'arc_to_0to2pi.py', > 'ClustersOfGalaxiesUtils.py', > 'extract_text_line.py', > 'LAMBDA_calc.py', > 'loop_to_sum.example.py', > 'number_theory.py', > 'omega_plasma_radHz.py', > 'script2_1.py', > 'toy_module.py', > 'uv2D.Feb14-06.py <http://uv2d.feb14-06.py/>', > 'VariablesInFile.py', > 'VLA_beamwidths.py', > 'z_cosmol.py'] > > In [20]: # Try changing the Python search path. > > In [21]: import sys > > In [22]: sys.path > Out[22]: > ['', > 'C:\\Python26\\scripts', > 'C:\\WINDOWS\\system32\\python26.zip', > 'C:\\Python26\\DLLs', > 'C:\\Python26\\lib', > 'C:\\Python26\\lib\\plat-win', > 'C:\\Python26\\lib\\lib-tk', > 'C:\\Python26', > 'C:\\Python26\\lib\\site-packages', > 'C:\\Python26\\lib\\site-packages\\IPython/Extensions', > u'C:\\Documents and Settings\\Hornstein\\_ipython'] > > In [23]: sys.path.append(function_dir) > > In [24]: sys.path > Out[24]: > ['', > 'C:\\Python26\\scripts', > 'C:\\WINDOWS\\system32\\python26.zip', > 'C:\\Python26\\DLLs', > 'C:\\Python26\\lib', > 'C:\\Python26\\lib\\plat-win', > 'C:\\Python26\\lib\\lib-tk', > 'C:\\Python26', > 'C:\\Python26\\lib\\site-packages', > 'C:\\Python26\\lib\\site-packages\\IPython/Extensions', > u'C:\\Documents and Settings\\Hornstein\\_ipython', > 'G:\\Python_2010-12\\JH_Python_Functions'] > > In [25]: import toy_module > > In [26]: result1 = toy_module.double_it(3.) > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > > G:\Python_2010-12\JH_Python_Functions\<ipython console> in <module>() > > AttributeError: 'module' object has no attribute 'double_it' <<< 3 > > In [27]: exit() > Do you really want to exit ([y]/n)? > > > Any insight would be appreciated. > > Also, it is unfortunate that no warning is issued when an attempt at > importing fails. > > John Hornstein > > > (By the way, I am stuck with Python2.6 because the binary installer for > NumPy on Windows still refuses to accept any later version of Python.) > > > > ---------- Forwarded message ---------- > From: Slie <stacks...@gmail.com> > To: python-list@python.org > Date: Wed, 5 Jan 2011 16:31:13 -0900 > Subject: Searching Python-list > I was wondering if anyone could tell me how to search through the Archives > otter then manually looking through each month. > > > > > ---------- Forwarded message ---------- > From: Adam Skutt <ask...@gmail.com> > To: python-list@python.org > Date: Wed, 5 Jan 2011 17:25:49 -0800 (PST) > Subject: Re: Interrput a thread > On Jan 4, 10:53 pm, John Nagle <na...@animats.com> wrote: > > There are systems where there's support designed in for thread > > abort. LISP/Scheme systems tend to support it. QNX, the real-time > > OS, has well worked out thread-abort semantics at the C level. > > (QNX has really good features for "not getting stuck", like the > > ability to put a time limit on any system call.) > > Yes, but "not getting stuck" and ending the thread execution is only > one small part of the problem (and arguably the least significant). > What we really want is a way to abort without harming other threads of > execution, which is the hard part. QNX doesn't ipso facto make that > easier. Functionality like time limits on system calls is more about > latency guarantees and priority than "getting stuck" in a deadlock > sense. > > > What you'd really like in Python is the ability for one thread > > to be able to force an exception in another thread, plus a > > mechanism for locking out such exceptions for critical sections. > > It's not worth having, though, in a system where you can really only > > run one thread at a time. > > Exceptions and critical sections are rather fundamentally > incompatible, hence the absurd amount of gymnastics .NET goes through > to attempt to make ThreadAbortException functional (and still fails > rather miserably). If you had STM or 'antitry' blocks, then > exceptions might be a semi-saneish way to abort a thread. Without > either, I'm not entirely convinced of the utility. > > Only allowing the exception to be thrown from defined cancellation > points is much better (ala POSIX threads), but diminishes the utility > for things that are mostly grinding away in userspace. > > Adam > > > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list