Re: Reading a two-column file into an array?
On Jul 31, 9:03 am, Gilles Ganault <[EMAIL PROTECTED]> wrote: > Hello > > I'm sure there's a much easier way to read a two-column, CSV file into > an array, but I haven't found it in Google. > > Should I use the Array module instead? > > = > a = [] > i = 0 > > #itemitem > p = re.compile("^(.+)\t(.+)$") > > for line in textlines: > m = p.search(line) > if m: > a[i,0] = m.group(1) > a[i,1] = m.group(2) > i = i + 1 > > for i in a.count: > for j in 2: > print a[i,j] > === > > Thank you. a = [] import csv reader = csv.reader(open("filename", "r"), delimiter='\t' ) for row in reader: a.append( row ) I don't think you can have multidimensional arrays. Did you test you program? It did not work for me. I think mine would suit your requirements as the output is a list of lists. -- http://mail.python.org/mailman/listinfo/python-list
Server-side scripting in python
Hi group, I need to develop a web application. I am in a fix as to choose among the various server-side scripting options. I want to explore python (am a newbie) to gain expertise and upon search, I learnt about PSP(Python Server Pages) that uses Jython as its scripting language. Is it a better option over PHP or Perl? Could anyone point out the pros and cons of using PSP over others? Help much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Server-side scripting in python
On Aug 21, 6:40 pm, [EMAIL PROTECTED] (Cameron Laird) wrote: > In article <[EMAIL PROTECTED]>,Nagarajan <[EMAIL PROTECTED]> wrote: > >Hi group, > >I need to develop a web application. I am in a fix as to choose among > >the various server-side scripting options. I want to explore python > >(am a newbie) to gain expertise and upon search, I learnt about > >PSP(Python Server Pages) that uses Jython as its scripting language. > >Is it a better option over PHP or Perl? Could anyone point out the > >pros and cons of using PSP over others? > > . > . > . > I suspect that several of us don't understand your question. > > Python supports several--arguably, a plethora, more than any other > language--distinct "frameworks" for server-side scripting of Web > applications http://wiki.python.org/moin/WebFrameworks>. > PSP certainly is among these, although it's recommended > http://colorstudy.com/docs/shootout.html> less often than > several others. Is PSP better than PHP or Perl? First, do you > understand that PSP isn't directly comparable to PHP or Perl? The > latter two are languages, while PSP is a Web framework. In any > case, the answer is certain to be, "it depends". There certainly > are situations for each of PSP, PHP, Perl, and many other technol- > ogies. > > I summarize: if you have an interest in practicing Python while > building Web applications, your prospects certainly are bright; > you'll receive abundant help from the folks here and elsewhere. > For us to provide more specific details about Perl, PSP, and so > on, meaningful to your own needs, will only be possible when you > articulate the latter more fully > http://catb.org/~esr/faqs/smart-questions.html>. Let me phrase my problem in a finer way. I have done simple projects in python. I wanted to explore web programming facet of python. The problem at my hand is to develop an email web client. I've developed web applications in PHP. I need to evaluate python-based web frameworks to make a smart choice of the web framework or a language like PHP, Perl based on performance predominantly. Do I make myself clear now? Thanks for all the help extended. -- http://mail.python.org/mailman/listinfo/python-list
Re: Server-side scripting in python
On Aug 22, 8:50 pm, [EMAIL PROTECTED] (Cameron Laird) wrote: > In article <[EMAIL PROTECTED]>,Nagarajan <[EMAIL PROTECTED]> wrote: > > >> . > >> . > >> . > >Let me phrase my problem in a finer way. > >I have done simple projects inpython. > >I wanted to explore web programming facet ofpython. The problem at my > >hand is to develop an email web client. I've developed web > >applications in PHP. I need to evaluatepython-based web frameworks to > >make a smart choice of the web framework or a language like PHP, Perl > >based on performance predominantly. Do I make myself clear now? > > . > . > . > In general, network latency is likely to dominate the performance > of a hobbyist-scale Webmail application coded in PHP, Perl, orPython; to base > your decision predominantly on performance is ... > well, it's not what I'd recommend. You might as well flip a coin. > > Flipping a coin isn't such a bad idea; it's possible to write good > applications with any of PHP, Perl, andPython. Even if you restrict > yourself toPython, you can flip another coin and choose almost any > of its Web frameworks. > > I salute your intent to choose a Web framework wisely. In the ab- > sence of still more detail about your situation, requirements, > constraints, ..., I don't know how to do so beyond what I've already > written. Django is intuitive and handy. I think I would go with that. Any suggestions? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Raw strings to normal strings conversion?
Is there a way by which I could obtain normal string form of a raw string. XML CDATA is returned as raw string. But I need the string to actually escape special chars. Any idea? -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw strings to normal strings conversion?
On Aug 23, 1:21 pm, James Stroud <[EMAIL PROTECTED]> wrote: > Nagarajan wrote: > > Is there a way by which I could obtain normal string form of a raw > > string. > > XML CDATA is returned as raw string. But I need the string to actually > > escape special chars. > > > Any idea? > > This doesn't seem clear. Perhaps an example of what you get and what you > want it converted to. Here is an example: >> rawstr = r'a\nb' >> print rawstr a\nb Now I need this newstr to actually interpret '\n', in other words, to behave like a normal string. > > In the meantime, see if urllib.unquote() doesn't do what you need. > > James And yes, unquote doesn't help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw strings to normal strings conversion?
On Aug 23, 2:42 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 23 Aug 2007 09:21:40 +, Nagarajan wrote: > > On Aug 23, 1:21 pm, James Stroud <[EMAIL PROTECTED]> wrote: > >> Nagarajan wrote: > >> > Is there a way by which I could obtain normal string form of a raw > >> > string. > >> > XML CDATA is returned as raw string. But I need the string to actually > >> > escape special chars. > > >> > Any idea? > > >> This doesn't seem clear. Perhaps an example of what you get and what you > >> want it converted to. > > > Here is an example: > >>> rawstr = r'a\nb' > >>> print rawstr > > a\nb > > > Now I need this newstr to actually interpret '\n', in other words, to > > behave like a normal string. > > So you get a string with Newlines as two character sequence \n. You don't > get "raw" strings. That is a concept in Python source code. When the > program is running there is no such distinction between "raw" and "normal" > strings. Here's a solution: > > In [87]: print r'a\nb' > a\nb > > In [88]: print r'a\nb'.decode('string-escape') > a > b > > Ciao, > Marc 'BlackJack' Rintsch Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: XML File -- dictionary edit/search
On Aug 28, 6:15 am, -b <[EMAIL PROTECTED]> wrote: > I am trying to put together a python program that will be able to ask > for a word and its definition, then save that information into an xml > file for reference. I am not down right set on the file being in xml > format, but xml is the first thing that comes to mind, since I do not > want to use a MySQL database. I think xml will be easy to search and > return a word's definition--another reason why xml comes to mind first > after MySQL databases. Please, if you have any suggestions to what > python-xml libraries I might use to program this small app with, then > by all means voice your thoughts. Thank you very much for your time. A simple yaml file might just do the trick. Your yaml file shall look like the following: Word-def.yaml word1: word1's definition word2: word2's definition .. .. .. Use pyyaml to handle yaml files. import yaml worddefs = yaml.load( open( "word-def.yaml", "r" ).read() ) print worddefs worddefs will be a dictionary of words (with definitions as values, of course). You cannot get a better representation. To add a definition, you can as well add keys to the worddefs dictionary and use "dump" method to write to the yaml file. Or you could just write to the file directly (as the format is simple in this case). But I suggest former. Did this solve your problem? -Brevity is the soul of wit. Nagarajan. -- http://mail.python.org/mailman/listinfo/python-list
less obvious "super"
Hi group, I am confused with "super" usage..It seems to be complicated and less obvious. Here is what I need to achieve.. class A : def __init__( self ): self.x = 0 class B ( A ): def __init__( self, something ): # Use "super" construct here so that I can "inherit" x of A self.y = something How should I use "super" so that I could access the variable "x" of A in B? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: less obvious "super"
On Sep 10, 4:20 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Nagarajan <[EMAIL PROTECTED]> wrote: > > Here is what I need to achieve.. > > > class A : > > def __init__( self ): > > self.x = 0 > > Don't use old style classes. If you are planning to use 'super' then you > must use new-style classes, so use 'object' as a base class here. > > > > > class B ( A ): > > def __init__( self, something ): > > # Use "super" construct here so that I can "inherit" x of A > > self.y = something > > > How should I use "super" so that I could access the variable "x" of A > > in B? > > If you aren't worried about diamond shaped multiple inheritance > hierarchies then just use: > > class B ( A ): > def __init__( self, something ): > A.__init__(self) > self.y = something > > If you are then: > > class B ( A ): > def __init__( self, something ): > super(B, self).__init__() > self.y = something > > When you use super you usually just want the current class and current > instance as parameters. Putting that together: > > >>> class A(object): > > def __init__( self ): > self.x = 0 > > >>> class B ( A ): > > def __init__( self, something ): > super(B, self).__init__() > self.y = something > > > > >>> obj = B(3) > >>> obj.x > 0 > >>> obj.y > 3 What's the difference b/w: class A : and -- http://mail.python.org/mailman/listinfo/python-list
Re: less obvious "super"
On Sep 10, 4:20 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Nagarajan <[EMAIL PROTECTED]> wrote: > > Here is what I need to achieve.. > > > class A : > > def __init__( self ): > > self.x = 0 > > Don't use old style classes. If you are planning to use 'super' then you > must use new-style classes, so use 'object' as a base class here. > > > > > class B ( A ): > > def __init__( self, something ): > > # Use "super" construct here so that I can "inherit" x of A > > self.y = something > > > How should I use "super" so that I could access the variable "x" of A > > in B? > > If you aren't worried about diamond shaped multiple inheritance > hierarchies then just use: > > class B ( A ): > def __init__( self, something ): > A.__init__(self) > self.y = something > > If you are then: > > class B ( A ): > def __init__( self, something ): > super(B, self).__init__() > self.y = something > > When you use super you usually just want the current class and current > instance as parameters. Putting that together: > > >>> class A(object): > > def __init__( self ): > self.x = 0 > > >>> class B ( A ): > > def __init__( self, something ): > super(B, self).__init__() > self.y = something > > > > >>> obj = B(3) > >>> obj.x > 0 > >>> obj.y > 3 What's the difference b/w: class A: and class A ( object ): Thanks. -- http://mail.python.org/mailman/listinfo/python-list