Re: Newbie, homework help, please.
A lot of to do about this.
---
#!/usr/bin/python
xl = ["First Name and Last","ENGR 109-X","Fall 2999","Format Example"]
xl_max = 0
for x in xl:
xl_max = max ( len( x ), xl_max )
topBorder = '^'*( xl_max + 4 )
print topBorder
for x in xl:
print "* %s%s *" % ( x, ' '*(xl_max - len( x )) )
print topBorder
---
On Saturday, April 21, 2012 10:28:33 AM UTC-7, someone wrote:
> Ok, this is my dillema, not only am I new to this programming buisness,
> before the last few days, I did not even know what python was, and besides
> opening up the internet or word documents, that is most of what I know. Yet,
> I have a professor who should be on Psych medication for giving us 3
> projects, 2 of which I have not listed here to do. I was able to do research
> over the last 3 days, and I have spent 3 days on this project, by borrowing
> others ideas on this project. Below, you will find my professors assignment
> (oh, and due in one week right before finals, so I am stressing out so much,
> cause I don't know why he is crazy enough to assign crap like this a week
> before finals when I have Calculus final,chem final, etc. I have figured out
> most of the assignment, and below, it will be posted after the teacher's post
> of the assignment. What I need help with, and I have tried relentlessly to
> find, is how to put freaking stars(asterisks) as border around a list without
> installing any other program to a portable python, of course, this is where
> my problem lies. Below, you will see what I have done, please, help!!!
> You are required to complete and submit the following programming projects in
> Python by the indicated deadline:
>
> Standard Header Information project (5 pts):
> Write a program that will:
> 1) Ask the user for the following information:
> - name of file to be created for storing SHI
> - user’s name (as part of SHI)
> - user’s course and section (as part of SHI)
> - user’s semester and year (as part of SHI)
> - user’s assignment title (as part of SHI)
> 2) Write the above SHI data to a text (.txt) file with the name chosen by the
> user (above)
> 3) Close the file that the SHI data was written to
> 4) Open the file with the SHI data (again)
> 5) Read the data into different (from part 1) variable names
> 6) Display the SHI data read from the file in the interpreter with a border
> around the SHI data (include a buffer of 1 line/space between the border and
> SHI data). An example might look like:
>
> ***
> * *
> * First Name and Last *
> * ENGR 109-X *
> * Fall 2999 *
> * Format Example *
> * *
> ***
>
>
> textfile=input('Hello, we are about to create a text file. An example would
> be: (sample.txt) without the parenthesis. What ever you do name it, it needs
> to end in (.txt). What would you like to name your textfile?')
> userinput=[input('What is your name?'),input('What is your Course Section and
> Course number?'),input('What is the Semester and year?'),input('What is the
> title of this class assignment?')]
> for item in userinput:
> openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in
> userinput);openfile.close()
> x=textfile;indat=open(x,'r');SHI=indat.read()
> def border(Sullivan):
> string=SHI
> stringlength=len(string)
> stringlength=stringlength("%s\n" % item for item in stringlength) + 2 *
> (3 + 3)
> hBorder=stringlength//2*"* "+"*"[:stringlength%2]
> spacer="*"+" "*(stringlength - 2)+"*"
> fancyText="* "+string+" *"
> return(hBorder,spacer,fancyText,hBorder)
>
> textTuple = border(SHI)
> for lines in textTuple:
> print (lines)
--
http://mail.python.org/mailman/listinfo/python-list
Purely historic question: VT200 text graphic programming
Once, many, many, years ago, I programmed some type of 'graphical' interface on a VT200 terminal (only DEC VAX/VMS programmers are going to know what this is). Question. What was the library I linked against? Yes, you remember, painting boxes with ascii and the superset of ascii. Thanks for the reminder. Steven Howe -- http://mail.python.org/mailman/listinfo/python-list
Re: Purely historic question: VT200 text graphic programming
Yes, Curses, how could I forget that. Thanks Steven On Thu, 10 Mar 2011 05:34:35 -0500, Adam Tauno Williams wrote: > On Thu, 2011-03-10 at 00:38 -0600, GrayShark wrote: >> Once, many, many, years ago, I programmed some type of 'graphical' >> interface on a VT200 terminal (only DEC VAX/VMS programmers are going >> to know what this is). Question. What was the library I linked against? >> Yes, you remember, painting boxes with ascii and the superset of ascii. > > It was curses [ these days people typically use "ncurses" ]. There > really isn't anything historic about it, it is used in many current > projects/products - basically anything that will run in a gnome-terminal > [such as YaST] uses ncurses. It works very well from Python. [for > example: > http://www.whitemiceconsulting.com/2010/01/python-curses-in-action-even- on-aix.html > ] There are several higher level 'wrappers' for ncurses these days. > > Docs @ <http://docs.python.org/howto/curses.html> -- http://mail.python.org/mailman/listinfo/python-list
Re: Purely historic question: VT200 text graphic programming
On Thu, 10 Mar 2011 18:02:41 +, Grant Edwards wrote: > On 2011-03-10, Adam Tauno Williams wrote: >> On Thu, 2011-03-10 at 00:38 -0600, GrayShark wrote: >>> Once, many, many, years ago, I programmed some type of 'graphical' >>> interface on a VT200 terminal (only DEC VAX/VMS programmers are going >>> to know what this is). Question. What was the library I linked >>> against? Yes, you remember, painting boxes with ascii and the superset >>> of ascii. >> >> It was curses [ these days people typically use "ncurses" ]. > > Curses that can't be what the OP is referring to. > > Curses wasn't a VAX/VMS thing, it was a Unix thing (that has been ported > to other platforms as well). VMS did have it's own text-screen-widget > library sort of like curses+panel, but I don't remember what it was > called. Some googling coughs up FMS and DECforms. I vageuly remember > using one or the other, but that was a long time ago (25 years). > > At first first I thought he was talking about ReGIS, but that wasn't > available on the vt200 (it was on vt240/330/340). Actually it was curses; it came with the C compiler. What was more entertaining was that I using a legacy Fortran program, DEC Fortran (actually had pointers!) and linking to a C curses interface. Most exciting. The rest of the project was about realtime data collect and processing on a microvax III. In the mid-90, that wasn't doable at 1 milliscond time steps. VMS was just not realtime aware. GrayShark. -- http://mail.python.org/mailman/listinfo/python-list
Re: Purely historic question: VT200 text graphic programming
On Fri, 11 Mar 2011 11:17:08 +0200, Anssi Saari wrote: > Grant Edwards writes: > >> C wasn't very widely used under VMS, and VMS had it's own screen >> formatting and form handling libraries. > > Just curious, what language was widely used in VMS? My VMS experience is > limited to running Maple for a math course in the university in early > 1990s. Didn't know how to do much more than start Maple, probably just > dir, logout (or was it logoff?) and ftp :) I used Fortran and C. Pascal was pretty popular then as was BASIC; likely included. I know there was an Ada compiler as well; required by DOD, as it was the 'language of choice'. Some days the DOD is just foolish, dictating what must work better on hardware. Sort of like the need to push Java or C-Sharp on everything. Ada always reminded me of Cobol. Oh yes, Cobol also worked on VMS (yikes! the columns just right issues!). I remember a Properties officer, upset that I wanted pricing data included in the printout. Adding that was beyond the 132 character output of the page. She seemed quite upset when I asked just for the 4 of 18 columns I was interested in, be printed. By 1998, Cobol programs were rare (although the language was pretty easy to learn). So: Fortran, C, Pascal, Cobol, Ada and ... APL. Let's see how many remember that very fun language (and I mean fun). GrayShark -- http://mail.python.org/mailman/listinfo/python-list
Re: Purely historic question: VT200 text graphic programming
On Fri, 11 Mar 2011 00:26:37 -0800, Dennis Lee Bieber wrote: > On Thu, 10 Mar 2011 19:55:02 + (UTC), Grant Edwards > declaimed the following in > gmane.comp.python.general: > >> vt200 terminals. The vt200 wasn't a TV. It was a character-based, >> mostly-ANSI-escape-sequence, computer terminal connected via async > > I think the order went the other way -- I think most of the ANSI > sequences were inherited from the VT52/VT100 terminals. Are you implying ascii came after the VT52/VT110 terminals? VT52 is a ascii code based piece of shit, including the backspace/return character set (which Windows still honors like it's a deity). Working from the old days, the ascii set used 0->127 (zero -> seventh bit) to represent special keys and sounds, letters, numbers and common punctuations. The eight bit was reserved for error correct. Remember this was a serial 'printer' console language. It need updating as much as the QWERTY keyboard does. Sometime after 1975, graphical glyphs were added, using the eighth bit. Some VT models supported the extended ascii, as did IBM-DOS. Strange the history one remembers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Purely historic question: VT200 text graphic programming
Aw! to stray down memory lane. Well enough straying. Back to work. GrayShark -- http://mail.python.org/mailman/listinfo/python-list
Re: Purely historic question: VT200 text graphic programming
On Fri, 11 Mar 2011 15:58:20 +, Grant Edwards wrote: > On 2011-03-11, Anssi Saari wrote: >> Grant Edwards writes: >> >>> C wasn't very widely used under VMS, and VMS had it's own screen >>> formatting and form handling libraries. >> >> Just curious, what language was widely used in VMS? > > From what I remember, FORTRAN what probably the most popular. Pascal > was also well supported and somewhat widely used (especially in > academia). Then there was BLISS-32 for the low-level stuff. C seemed > to be an afterthought and had a very "kludged" feel to it. VMS's file > I/O didn't correspond very will with the C byte stream model, and C's > view of line-termination didn't play well with everything else. > >> My VMS experience is limited to running Maple for a math course in the >> university in early 1990s. Didn't know how to do much more than start >> Maple, probably just dir, logout (or was it logoff?) and ftp :) I don't remember much of any language being that portable. I do remember it was very easy to take DEC Fortran and compile it without much issue on SGI/Irix. Much more scary was a program converted to C from Fortran (there were precompiler for that) ran slow on Irix then straight Fortran. That was godsend for simulation engineers. I agree, VAX/VMS's i/o model was slow in C. In fortran it was fast as they did all the opens when the program started, regardless of where the open statement was in the code. I even had a legacy program, open and close a file in a subroutine (a no no) that ran fast; debugging code. DEC fortran only opened the file once. Had some way of deciding if a write was an overwrite or an append. The program ran fast as 'normal' (that being without the open and close). When I ported the program to an Moto 88000 daughter processor board, the program ran slow as hell. The 88000 board used a Fortran->C compiler, that obeyed the open and close statements. Each time the program ran that subroutine, It opened, then closed a log file. Each statement required the daughter board to call, via the q-bus, the host OS (VMS), stop, wait for VMS to open a file, continue, then stop, wait for VMS to close the file. The correction was easy, get rid of the legacy debug code. The coder had never used the debugger program or a profiler; amazing! Well after both, debugging code removed and a run through a profile, the code ran fast as hell. 20 sims in the time the microvax III did one. That was probably the only reason we didn't move off VAX/VMS (that and old programmer inertia). Inertia, friend and foe. Otherwise I worked with a host of government contractors, each with their own version of C; each used their specialized version to prevent tax payer contracts from going to another contractor. Thank goodness for standardization. Finally the DOD could drop CSC or EDS over priced contracts to maintain code. Unfortunately, could, should and did don't have the same meaning at the end of the day. GrayShark. -- http://mail.python.org/mailman/listinfo/python-list
Re: From Python on Solaris to Python on LINUX
I think that was more of a version question the Kernel questin 1) you can install any and all versions python on a linux computer. You just need you app to select the correct path, correct python interpret. Likely there many be some some drivers in /dev that are not the same as in Solaris. But that shouldn't daunt you. So start by installing python2.3, then test and fix version by version through python2.7. python3.0 might be a pretty be rewrite. 2) Try to pick a version of linux supported locally; likely SuSE, even though Novell/Attachmate owns it. SuSE seems popular in Europe. On Thu, 15 Sep 2011 18:26:04 +0200, Philipp Hagemeister wrote: >> What are the traps to be avoided? > > Assuming you're not using any OS features (scan the code for "/dev" and > "/proc"), the transition from Solaris to Linux will be seamless. > > Your main problem will be the transition from the archaic Python 2.3 to > a modern one. Luckily, all 2.x Pythons should be backwards-compatible. > > In summary, your application should work just fine (although being > written in 2.3, it's probably not as maintainable as a modern > application would). > >> What is the most recent version on LINUX? > There are multiple Linux distributions which can differ quite a lot. > debian, Ubuntu, and CentOS are popular ones. As you can see on > http://www.debian.org/CD/ , the current debian version is 6.0. As you > can't see at the moment on http://kernel.org/ , the current Linux kernel > version is 3.0 (although most distribution will want to test the kernel > and therefore include a slightly older one). > > -- Philipp -- http://mail.python.org/mailman/listinfo/python-list
seeking pygtk bindings for gtkdatabox
Hello, a search for the python bindings for gtkdatabox lead no where. Anyone know of who is maintaining/working/siting such a package? Thanks in advance. Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Scanning directories for new files?
On Tue, 21 Dec 2010 14:17:40 -0500, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, remove > extra data that isn't needed, normalize some values, etc. The base files > will be uploaded via FTP. > How does one go about scanning a directory for new files? For now we're > looking to run it as a cron job but eventually would like to move away > from that into making it a service running in the background. You can try pyinotify. Pyinotify is a Python module for monitoring filesystems changes. Pyinotify relies on a Linux Kernel feature (merged in kernel 2.6.13) called inotify. inotify is an event-driven notifier, its notifications are exported from kernel space to user space through three system calls. pyinotify binds these system calls and provides an implementation on top of them offering a generic and abstract way to manipulate those functionalities. I'm assuming your using Linux. You seem to be at least using UNIX (cron). read more at: http://pyinotify.sourceforge.net/ Steven -- http://mail.python.org/mailman/listinfo/python-list
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
--
http://mail.python.org/mailman/listinfo/python-list
Re: Fitness data program
On Sat, 15 Jan 2011 19:48:40 +, Katie T wrote: > On Sat, Jan 15, 2011 at 5:47 PM, Antonio Cardenes > wrote: >> Hello folks, I'm trying to improve my Phyton skills with a project: A >> fitness program that can correlate measurements (weight and size of >> various body parts), date taken and it has to be able to print a nice >> graph showing improvements (a la Wii Fit) > > Scipy + Matplotlib should give you the tools to do correlation stats and > graphing. > > Katie Likely you'll want a database, for usernames, dates, weights. Since it's so simple, using sqlite (which doesn't have a running database engine) is a wise choice. There's a python module to help interface. Also you might visit the django website. This sort of project could use a web frontend, since your likely want users to have access to their plots, so logins are required; Remote access (via web) sounds reasonable too. During those early days of shaping up, well, no one else need see my progress. Remember the old adage KISS (Keep It Simple, Stupid) steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Line breaks in list causing a small formatting problem while joining the list
On Fri, 21 Jan 2011 07:39:26 -0800, Oltmans wrote: > Hi Python gurus, hope you're doing well. I've a small problem. > > When I run the following code > ___ names = ['oltmans','abramhovic','\n','sal','lee'] print '| ' + ' | '.join(names) > | oltmans | abramhovic | > | sal | lee > ___ > > I get the output like above. However, I want it to output like below > > | oltmans | abramhovic | > | sal | lee > > > That is, there shouldn't be a space in the beginning of second line. The > list can of course contain more than 5 elements. Any ideas? I will > appreciate any hint. Thanks in advance. It looks like your trying to print a formatted list. With your code you are: 1) creating a string from a list, with added characters. 2) printing the new string. So, look at your string: names = ['oltmans','abramhovic','\n','sal','lee'] newNames = '| ' + ' | '.join( names ) >> newNames '| oltmans | abramhovic | \n | sal | lee' Now you can see your space after the newline (and a missing pipe symbol at the end). When you ask the compiler for newNames, you can see there is a space after the newline character. Naturally, the print operator prints out the space. If this is indeed a formatted list, you should try something else. Something like: # first get rid of you formatting element in the list '\n'. names = [ 'oltmans','abramhovic','sal','lee' ] # next iterate by twos via the function 'range( start, stop, step )' range( 0, len( names ), 2 ) [ 0, 2 ] # now fix up the printing by twos. >>> for x in range( 0, len( names ), 2 ): ... print '| %s | %s |' % ( names[ x ], names[ x + 1 ] ) ... | oltmans | abramhovic | | sal | lee | Next, make it pretty. The next step would be to find the longest string in your list. >>> def max( theList ): ... theMax = 0 ... for element in theList: ... if len( element ) > theMax: ... theMax = len( element ) ... return theMax >>> max( names ) 10 Now some centering of strings, from you list. >>> for x in range( 0, len( names ), 2 ): ... print '| %s | %s |' % \ ( names[ x ].center(10), \ names[ x +1 ].center(10) ) ... | oltmans | abramhovic | |sal |lee | Pretty list. Now make it obscure, like you are a perl programmer; don't forget to eat up memory as you go along def maxElement( aList ): lenList = [] for x in aList: lenList.append( len( x ) ) return sorted( lenList, reverse=True )[0] def formatLine( firstName, secondName, width ): return '| %s | %s | % \ ( firstName.center( width ), \ secondName.center( width ) ) theWidth = maxElement( names ) for x in range( 0, len( names ), 2 ): aLine = formatLines( names[x], names[x+1], theWidth ) print aLine Make sure to create at lest two additions files to store maxElement and formatLine, create an __init__.py and make a package, turn in the project and get expelled for being grandiose. steven. -- http://mail.python.org/mailman/listinfo/python-list
deprecated string module issue
In my code I have: from string import lower, upper When I use pylint on the program I get just one warning: Uses of a deprecated module 'string'. Iv'e noted that many if not all string functions are now in _builtin_. Where are the constants? Thanks Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: deprecated string module issue
On Jun 24, 10:06 am, GrayShark wrote: > In my code I have: > from string import lower, upper > > When I use pylint on the program I get just one warning: > > Uses of a deprecated module 'string'. > > Iv'e noted that many if not all string functions are now in _builtin_. > Where are the constants? > > Thanks > Steven Sorry, I meant "from string import lowercase, uppercase" As I was joining these two, I just changed the import to 'letters' So if the constants are not deprecated, why is the module? Is some other state then deprecated needed to describe functions and/or methods deprecated, but not whole modules? It just seems wrong, this all or nothing state. Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: deprecated string module issue
On Fri, 25 Jun 2010 01:29:22 +, Benjamin Peterson wrote: > GrayShark gmail.com> writes: > >> Sorry, I meant "from string import lowercase, uppercase" > > Technically, you should use ascii_lowercase and ascii_uppercase, though > I don't know if that's the cause of pylint's complaints. Thanks for the suggestion. I gave it a quick try. Same 'warning'. No, using the string module is the issue. Perhaps I'll just ignore it. sph -- http://mail.python.org/mailman/listinfo/python-list
Re: deprecated string module issue
Why the rudness Terry Jan Reedy? Get up on the wrong side of the bed? Or worse luck, no one on the other side to create a wrong side? As to your comment about Logilab's pylint. I'v seen a ticket similar to this from three months back. I assume they're not fixing it because if you review 'string' via pydoc you'd read this: --- Help on module string: NAME string - A collection of string operations (most are no longer used). FILE /usr/lib64/python2.6/string.py DESCRIPTION Warning: most of the code you see here isn't normally used nowadays. Beginning with Python 1.6, many of these functions are implemented as methods on the standard string object. They used to be implemented by a built-in module called strop, but strop is now obsolete itself. --- Not the 1.6. Seems some serious work went into putting the 'string's functionality into _builtin_. I've seen many 'deprecated' warnings when programming in PyGTK, as modules get replaced or functionality changes. I've always assumed it means that the module will be removed at some future date. An advisory to programmers and users. -- You might note what 'deprecated' means. http://www.thefreedictionary.com/ deprecated tr.v. de·pre·cat·ed, de·pre·cat·ing, de·pre·cates 1. To express disapproval of; deplore. 2. To belittle; depreciate. 3. Computer Science To mark (a component of a software standard) as obsolete to warn against its use in the future so that it may be phased out. --- Not the third definition. It applies here. I was inquiring about what other module I should be using instead, having grep'ped my way through /usr/lib64/python2.6/*.py for a replacement. Nor a naive user here. Been programming/using python since 2000 (java, C++, C, APL, Fortan and Basic before that). Python's my favorite place to do math (since I don't have an APL environment anymore, where a cross or dot product is just a single operator away). I decided to ask a question about an issue that's been on my mind for years. Not really sorry if that bother's your incorrect belief of who can ask questions. There are subjects for each posting. Perhaps you should just ignore ones that aren't interesting to you? Or get a life and a girl/boy friend, so you'll have less time to make snipping remarks (check out: 'http://www.thefreedictionary.com/snipe' if you don't understand snipe). have a better day. GrayShark. On Fri, 25 Jun 2010 16:10:23 -0400, Terry Reedy wrote: > On 6/25/2010 10:02 AM, GrayShark wrote: > >> Thanks for the suggestion. I gave it a quick try. Same 'warning'. No, >> using the string module is the issue. Perhaps I'll just ignore it. > > And what about the next naive user of pylint? Submitting a bug report to > the author of pylint would take much less time than you have *us* to > spend helping you. Doing so would be a way of thanking us since then, if > pylint were changed, we would not have to answer the same question again > in a year. -- http://mail.python.org/mailman/listinfo/python-list
refactoring a group of import statements
I have a large list of package files to import. I'm using a try/except
test to verify the import. Looks like:
try:
import abc
except ImportError:
print( "Error importing abc" )
I've got many of those segments. I want to try and refactor this part
of the code.
Trying:
for mod in ['ab', 'cd', 'ef' ]:
try:
mod = __import__( mod )
except ImportError:
print( "Error importing %" % mod )
This of course doesn't work. The module ab get's assign in the application
as mod.
Tried:
for mod in ['ab', 'cd', 'ef' ]:
('%s' % mod ) = __import__( mod )
Still no joy.
I need a way to deference the the string in mod to be just a variable.
Any suggestions?
GrayShark
--
http://mail.python.org/mailman/listinfo/python-list
Re: refactoring a group of import statements
Thanks for the help Thomas Jollans. Just what I needed. I was wondering
what the:
__import__(name, globals={}, locals={}, fromlist=[], level=-1)
globals was (that was from the docstring on __import__. Odd, the doc on
www.python.org has globals as a list, not a dictionary). In any case, I
had a feeling it was the answer; I just didn't know how to do it.
--Example test--
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:31)
[GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> x = 'string'
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'x']
>>> globals()[x] = __import__( x )
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__', 'string', 'x']
>>>
--ends--
That was what I was looking for. All the rest, the arguments were
unhelpful.
Question: If you can't answer the question, why are you talking?
I'm American Indian. That's what I was taught. We don't talk that much.
But you get an answer when we do talk. Makes life simpler.
Thanks you again Thomas Jollans.
GrayShark
On Mon, 28 Jun 2010 00:18:36 +0200, Thomas Jollans wrote:
> On 06/28/2010 12:06 AM, GrayShark wrote:
>> I have a large list of package files to import. I'm using a try/except
>> test to verify the import. Looks like:
>>
>> try:
>> import abc
>> except ImportError:
>> print( "Error importing abc" )
>>
>> I've got many of those segments. I want to try and refactor this part
>> of the code.
>>
>> Trying:
>> for mod in ['ab', 'cd', 'ef' ]:
>> try:
>> mod = __import__( mod )
>> except ImportError:
>> print( "Error importing %" % mod )
>>
>> This of course doesn't work. The module ab get's assign in the
>> application as mod.
>>
>> Tried:
>> for mod in ['ab', 'cd', 'ef' ]:
>> ('%s' % mod ) = __import__( mod )
>>
>> Still no joy.
>>
>> I need a way to deference the the string in mod to be just a variable.
>>
>> Any suggestions?
>
> (1) Don't. If you need the module, there's no reason to check for
> exceptions. Just let the ImportError propagate. Okay, maybe you don't
> actually need the module - then why do you have to import it in the
> first place?
>
> (2) globals()[mod] = __import__(mod)
>
> (3) Why not
>
> try:
> import x
> import y
> import z
> except ImportError as exc:
> display_error_properly(exc)
> raise exc
>
>
> -- Thomas
--
http://mail.python.org/mailman/listinfo/python-list
Re: PIL
As we seem to be at an impasse with respect to PIL and xpm, I know gimp does support saving as xpm and that gimp has a python language console. Perhaps [email protected], could look to the gimp mailing list for help? Steven On Tue, 03 Aug 2010 01:56:20 -0700, Chris Rebert wrote: > On Tue, Aug 3, 2010 at 1:45 AM, Navid Parvini > wrote: >> Dear All, >> >> I want to convert a .png file to .xpm using PIL. I used the following >> command: Image.open( "t1.png").save("a1.xpm"). But it doesn't work and >> I could not convert it. >> >> Would you please help me and let me know that how can I convert/save >> .xpm files in PIL. > > PIL only supports reading .XPM, not writing .XPM: > http://www.pythonware.com/library/pil/handbook/format-xpm.htm > > Cheers, > Chris -- http://mail.python.org/mailman/listinfo/python-list
