unexpected regexp behaviour using 'A|B|C.....'

2011-07-28 Thread AlienBaby
When using re patterns of the form 'A|B|C|...'  the docs seem to
suggest that once any of A,B,C.. match, it is captured and no further
patterns are tried.  But I am seeing,

st='  Id NameProv Type  CopyOf  BsId
Rd -Detailed_State-Adm Snp  Usr VSize'

p='Type *'
re.search(p,st).group()
'Type  '

p='Type *|  *Type'
re.search(p,st).group()
' Type'


Shouldn’t the second search return the same as the first, if further
patterns are not tried?

The documentation appears to suggest the first match should be
returned, or am I misunderstanding?

'|'
A|B, where A and B can be arbitrary REs, creates a regular expression
that will match either A or B. An arbitrary number of REs can be
separated by the '|' in this way. This can be used inside groups (see
below) as well. As the target string is scanned, REs separated by '|'
are tried from left to right.

 When one pattern completely matches, that branch is accepted. This
means that once A matches, B will not be tested further, even if it
would produce a longer overall match.

In other words, the '|' operator is never greedy. To match a literal
'|', use \|, or enclose it inside a character class, as in [|].


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-26 Thread AlienBaby
 (on limiting line lengths)..

I didn't see this mentioned;

I have a hard time keeping python code limited to 80 char line lengths
_because_ indentation is significant, and can end up consuming quite a
lot of linespace itself.  Couple that with a liking for
long_memorable_explanatory_names, and an 80 char limit causes (me)
problems.

So I tend to use the print margin just as a guide. If I am over it,
then don't panic! just don't put any new elements onto the line, and
maybe step back and think about what your doing just in case theres
another clear way that avoids the issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


using an instance of Object as an empty class

2011-06-29 Thread AlienBaby
Hi,

I'm just wondering why something is so, and whats going on under the
hood.

Now and again I use something like

class empty(object):
 pass


simply so I can make an instance, and set some attributes on it.

a=empty()
a.whatever=something


Poking around with this, I assumed I could instead say

a=object()
a.whatever=something

but I get an attribute error. 'object object has no attribute
whatever'

I tried setattr() but get the same result.


So, it seems to me there is something special about instances of
object, and making an empty class  that inherits from object, or
creating an instance of that class, is doing some 'magic' somewhere
that enables setting attributes etc..

Whats actually going on here, and why?

Matt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPad 2.7.1 Update 4 (Python on iPad and iPhone)

2011-06-28 Thread AlienBaby
On Jun 23, 2:07 pm, Jon Dowdall jon.dowdall+newsgr...@gmail.com
wrote:
 Hi All,

 I'm pleased to announce that PyPad (Python environment for iOS) 2.7.1
 Update 4 is now available in the iTunes App Store. New in this version
 is the ability to create custom modules. Modules can be independent or
 can include other user modules to build larger frame works.

 Plans for future versions include:
 Improved cursor handling in interactive mode.
 Access to the interactive command history.
 Modules to access iOS specific functionality.
 Additional documentation.
 Syntax highlighting.
 Improved script debugging support.

 Regards,

 Jon

Hi Jon,

I would be interested in having a play with this. How is it restricted
when running in the iPad?

thanks,

Matt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionaries and incrementing keys

2011-06-14 Thread AlienBaby
On Jun 14, 12:16 pm, Peter Otten __pete...@web.de wrote:
 Steve Crook wrote:
  I've always done key creation/incrementation using:

  if key in dict:
      dict[key] += 1
  else:
      dict[key] = 1

 Your way is usually faster than

  dict[key] = dict.get(key, 0) + 1

  Whilst certainly more compact, I'd be interested in views on how
  pythonesque this method is.

 You may also consider

 http://docs.python.org/library/collections.html#collections.defaultdicthttp://docs.python.org/library/collections.html#collections.Counter



How do those methods compare to the one I normally use;

try:
 dict[key]+=1
except:
 dict[key]=1

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert AWK regex to Python

2011-05-17 Thread AlienBaby
On May 17, 11:07 am, J jnr.gonza...@googlemail.com wrote:
 Hello,

 I have managed to get my script finished in the end by taking bits from 
 everyone who answered.  Thank you so much.  the finished query string looks 
 like this (still not the best but it gets the job done.  Once I learn to code 
 more with Python I will probably go back to it and re-write it):-

 # Log file to work on
 filetoread = open(/tmp/pdu.log, r)
 # Perform filtering in the log file
 text = filetoread.read()
 text = text.replace(G_, )
 text = text.replace(.,  )
 text = text.replace(r(,  )
 filetoread.close()
 # File to write output to
 filetowrite = file(/tmp/pdu_filtered.log, w)
 # Write new log file
 filetowrite.write(text)
 filetowrite.close()
 # Read new log and get required fields from it
 filtered_log =  open(/tmp/pdu_filtered.log, r)
 filtered_line = filtered_log.readlines()
 for line in filtered_line:
         field = line.split( )
         field5 = field[5].rsplit(_, 1)
         print field5[0], field[14], field[22]
 print Done

You can also process the lines and write them out to the new logfile
as you read them in first time around, rather than: read them in,
process them, write them out, read them in, process them, write them
out;

log_file=open(old_log_file,r)
output_file=open(new_log_file,w)
for line in log_file:
 line=line.replace(G_, ).replace(.,  ).replace((,  )
 tokens=line.split()
 tokens_5=tokens[5].rsplit(_,1)
 output.file_write('%s %s %s\n' % (tokens_5,tokens[14],tokens[22]))
output_file.close()
log_file.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


locale settings and date parsing under windows

2011-02-03 Thread AlienBaby
Hi,

I'm attempting to convert some date-time strings from a text file
under windows into a datetime object as returned by strptime()

However, the strings can represent dates in various formats based on
the country of origin, for example shortened month names etc.. are
different between countries.

I am trying to set the correct locale for strptime to work, but I'm
having a lot of trouble doing this under windows.


IE, wher the date is in the Danish Language,

import locale
locale.setlocale('LC_ALL',locale.normalize('da_DK'))

gives

locale.Error: unsupported locale string.

I have tried various ways but always hit the same error.

I understand setting LC_ALL may not be what I require, I was first
looking to simply get the locale setting correctly before I started
changing only the date-time specific elements.



Any help or pointers much appreciated. Current searching around is
revealing a fair amount of confusion..!


Thanks,

Matt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: locale settings and date parsing under windows

2011-02-03 Thread AlienBaby
On Feb 3, 10:22 am, AlienBaby matt.j.war...@gmail.com wrote:
 Hi,

 I'm attempting to convert some date-time strings from a text file
 under windows into a datetime object as returned by strptime()

 However, the strings can represent dates in various formats based on
 the country of origin, for example shortened month names etc.. are
 different between countries.

 I am trying to set the correct locale for strptime to work, but I'm
 having a lot of trouble doing this under windows.

 IE, wher the date is in the Danish Language,

 import locale
 locale.setlocale('LC_ALL',locale.normalize('da_DK'))

 gives

 locale.Error: unsupported locale string.

 I have tried various ways but always hit the same error.

 I understand setting LC_ALL may not be what I require, I was first
 looking to simply get the locale setting correctly before I started
 changing only the date-time specific elements.

 Any help or pointers much appreciated. Current searching around is
 revealing a fair amount of confusion..!

 Thanks,

 Matt.

As often happens, writing that out and the working through a bit more,
I resolved my own question.

It ended up being a simple matter of translating from posix codes to
windows codes, so 'fr_FR' becomes 'French_France'...

thanks,

MAtt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: locale settings and date parsing under windows

2011-02-03 Thread AlienBaby
On Feb 3, 12:13 pm, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 On 02/03/11 10:59, AlienBaby wrote:





  On Feb 3, 10:22 am, AlienBabymatt.j.war...@gmail.com  wrote:
  Hi,

  I'm attempting to convert some date-time strings from a text file
  under windows into a datetime object as returned by strptime()

  However, the strings can represent dates in various formats based on
  the country of origin, for example shortened month names etc.. are
  different between countries.

  I am trying to set the correct locale for strptime to work, but I'm
  having a lot of trouble doing this under windows.

  IE, wher the date is in the Danish Language,

  import locale
  locale.setlocale('LC_ALL',locale.normalize('da_DK'))

  gives

  locale.Error: unsupported locale string.

  I have tried various ways but always hit the same error.

  I understand setting LC_ALL may not be what I require, I was first
  looking to simply get the locale setting correctly before I started
  changing only the date-time specific elements.

  Any help or pointers much appreciated. Current searching around is
  revealing a fair amount of confusion..!

  Thanks,

  Matt.

  As often happens, writing that out and the working through a bit more,
  I resolved my own question.

  It ended up being a simple matter of translating from posix codes to
  windows codes, so 'fr_FR' becomes 'French_France'...

  thanks,

  MAtt.

 You might also want to have a look at the contents of:
 locale.locale_alias

 --
 mph- Hide quoted text -

 - Show quoted text -

I did for a bit..

I tried, for example with French

from locale.locale_alias, you can find

'fr_FR' aliases to 'fr_FR.ISO8859-1'

but trying,

locale.setlocale(locale.LC_ALL,'fr_FR.ISO8859-1')

gives

locale.Error: unsupported locale setting


I'm now just using a handbuilt dict that holds translations like

'fr_FR' : 'French_France'
'da_DK' : 'Danish_Denmark'

etc..

Thanks,

MAtt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Changing Locale for datetime.strptime conversions

2010-07-06 Thread AlienBaby
Hi,

I'm using datetime.strptime(string,format) to convert dates parsed
from a file into datetime objects.

However, the files come from various places around the world, and
strptime fails when non-english month names are used.

strptime says it converts month names using the current locales
version of the name.  I've looked into the locale module but can't see
how I would setup.change a locales date/time representations, I can
only see categories related to decimal number / currency
representations.

Can anyone show how I could change the locale such that strptime could
parse a date string that used say, German month names?

Thankyou
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing Locale for datetime.strptime conversions

2010-07-06 Thread AlienBaby
On 6 July, 10:55, AlienBaby matt.j.war...@gmail.com wrote:
 Hi,

 I'm using datetime.strptime(string,format) to convert dates parsed
 from a file into datetime objects.

 However, the files come from various places around the world, and
 strptime fails when non-english month names are used.

 strptime says it converts month names using the current locales
 version of the name.  I've looked into the locale module but can't see
 how I would setup.change a locales date/time representations, I can
 only see categories related to decimal number / currency
 representations.

 Can anyone show how I could change the locale such that strptime could
 parse a date string that used say, German month names?

 Thankyou

I just solved this I believe. I didnt spot LC_ALL or LC_TIME
previously.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing Locale for datetime.strptime conversions

2010-07-06 Thread AlienBaby
I'm still having a bit of trouble,  for example trying to set  the
locale to Denmark


locale.setlocale(locale.LC_ALL, locale.normalize('da_DK'))

returns with

locale.setlocale(locale.LC_ALL, locale.normalize('da_DK'))
  File C:\Python26\lib\locale.py, line 494, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting


Though, from the docs I understand normalize should return a local
formatted for use with setlocale?
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt signals/slots dialogs question

2010-06-07 Thread AlienBaby
Hi,

I'm just starting to get to grips with PyQt, and I'm having a bit of
trouble connecting slots / signals, or understanding how I should do
so to achieve what I am after.

I am trying to write an application that will display a sequence of
dialogs, with back / next / cancel buttons to step through the
dialogs. Each dialog will capture user input, ask the user to browse
for a file, present some radio-buttons for a selection etc..

I've put the dialogs together in Designer, and I come to startup the
app with a small piece of python code, create an instance of each
dialog, and then connect up the buttons to any methods needed to
control the movement through the dialogs etc.

I'm having a brain-freeze though, and just can't figure out what I
should be doing next, or the best approach to take.

for example, Currently I am thinking I would need to connect the
clicked() signal of the Next button on dialog 1 to a method say,
'dialog1Next' that would then hide dialog1 and show dialog2.  I would
then need to connect Dialog 2's clicked() signal of its next button to
a method called 'dialog2Next' that hides dialog2 and shows dialog3
etc...

I would also, for example,  need methods for dialog2Back,
dialog2cancel, dialog1cancel etc..

I'm having trouble figuring out how to setup the connections, and
where the slot-methods should live..

I have this so far;

from PyQt4 import QtCore, QtGui
from WELCOME import Ui_Dialog as welcomeDialog
from SOURCE_TYPE_SELECT import Ui_Dialog as sourceTypeSelectDialog
from SOURCE_TYPE_CONFIRMATION import Ui_Dialog as
sourceTypeConfirmationDialog
from ACCEPT_EULA import Ui_Dialog as acceptEulaDialog
from CONFIRM_REQUIREMENTS import Ui_Dialog as
confirmRequirementsDialog
from SOURCE_BINARY_LOCATE import Ui_Dialog as sourceBinaryLocateDialog
from SOURCE_BINARY_PROBLEMS import Ui_Dialog as
sourceBinaryProblemsDialog
from OUTFILE_LOCATE import Ui_Dialog as outfileLocateDialog
from OUTFILE_PROBLEMS import Ui_Dialog as outfileProblemsDialog
from COLLECTION_PROGRESS import Ui_Dialog as collectionProgressDialog
from OUTFILE_LOCATION import Ui_Dialog as outfileLocationDialog



class StartQT4(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.Welcome = welcomeDialog()
self.Welcome.setupUi(self)
self.SourceTypeSelect = sourceTypeSelectDialog()
self.SourceTypeConfirmation = sourceTypeConfirmationDialog()
self.AcceptEula = acceptEulaDialog()
self.ConfirmRequirements=confirmRequirementsDialog()
self.SourceBinaryLocate=sourceBinaryLocateDialog()
self.SourceBinaryProblems=sourceBinaryProblemsDialog()
self.OutfileLocate=outfileLocateDialog()
self.OutfileProbelms=outfileProblemsDialog()
self.CollectionProgress=collectionProgressDialog()
self.OutfileLocation=outfileLocationDialog

#Connect up next/back/cancel etc.. buttons

??? self.Welcome.connect(self.Welcome.welcomeNext,
QtCore.SIGNAL(clicked()),WelcomeNext)



def WelcomeNext():
#Code here to hide Welcome dialog and show SourceTypeSelect
dialog



if __name__ == __main__:
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())





My questions are, am I approaching this the right way, with a method
per action per dialog to move through the dialogs, and just how do I
setup the connections I need. I'm getting confused with scope etc. IE:
if the connect is right, and WelcomeNext fires, how can it refer to
myapp.SourceTypeSelect.show() or myapp.Welcome.hide()


Any help much appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt signals/slots dialogs question

2010-06-07 Thread AlienBaby
I've made a little progress;

This appears to setup a connection that fires when the welcomeNext
button in the Welcome dialog is clicked;

self.Welcome.welcomeNext.connect(self.Welcome.welcomeNext,QtCore.SIGNAL(clicked()),self.WelcomeNext)


In the StartQT4 class I now have the WelcomeNext method;

def WelcomeNext(self):
self.Welcome.setVisible(False)
self.SourceTypeSelect.setVisible(True)

Though I am now getting

AttributeError: 'Ui_Dialog' object has no attribute 'setVisible'

Which, is right. Because it's not really a QDialog class.

Instead of using a 'WelcomeNext' method as the slot, should I just
connect the clicked() signal to both the hide slot of the welcome
dialog and the show slot of the SourceTypeSelect dialog?  .. though
then where would any code I wanted to run say, (for the sake of
argument) between the hiding of one dialog and the showing of the
next?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt signals/slots dialogs question

2010-06-07 Thread AlienBaby
On Jun 7, 4:37 pm, Phil Thompson p...@riverbankcomputing.com wrote:
 On Mon, 7 Jun 2010 08:22:07 -0700 (PDT), AlienBaby
 matt.j.war...@gmail.com
 wrote:





  Hi,

  I'm just starting to get to grips with PyQt, and I'm having a bit of
  trouble connecting slots / signals, or understanding how I should do
  so to achieve what I am after.

  I am trying to write an application that will display a sequence of
  dialogs, with back / next / cancel buttons to step through the
  dialogs. Each dialog will capture user input, ask the user to browse
  for a file, present some radio-buttons for a selection etc..

  I've put the dialogs together in Designer, and I come to startup the
  app with a small piece of python code, create an instance of each
  dialog, and then connect up the buttons to any methods needed to
  control the movement through the dialogs etc.

  I'm having a brain-freeze though, and just can't figure out what I
  should be doing next, or the best approach to take.

  for example, Currently I am thinking I would need to connect the
  clicked() signal of the Next button on dialog 1 to a method say,
  'dialog1Next' that would then hide dialog1 and show dialog2.  I would
  then need to connect Dialog 2's clicked() signal of its next button to
  a method called 'dialog2Next' that hides dialog2 and shows dialog3
  etc...

  I would also, for example,  need methods for dialog2Back,
  dialog2cancel, dialog1cancel etc..

  I'm having trouble figuring out how to setup the connections, and
  where the slot-methods should live..

  I have this so far;

  from PyQt4 import QtCore, QtGui
  from WELCOME import Ui_Dialog as welcomeDialog
  from SOURCE_TYPE_SELECT import Ui_Dialog as sourceTypeSelectDialog
  from SOURCE_TYPE_CONFIRMATION import Ui_Dialog as
  sourceTypeConfirmationDialog
  from ACCEPT_EULA import Ui_Dialog as acceptEulaDialog
  from CONFIRM_REQUIREMENTS import Ui_Dialog as
  confirmRequirementsDialog
  from SOURCE_BINARY_LOCATE import Ui_Dialog as sourceBinaryLocateDialog
  from SOURCE_BINARY_PROBLEMS import Ui_Dialog as
  sourceBinaryProblemsDialog
  from OUTFILE_LOCATE import Ui_Dialog as outfileLocateDialog
  from OUTFILE_PROBLEMS import Ui_Dialog as outfileProblemsDialog
  from COLLECTION_PROGRESS import Ui_Dialog as collectionProgressDialog
  from OUTFILE_LOCATION import Ui_Dialog as outfileLocationDialog

  class StartQT4(QtGui.QDialog):
      def __init__(self, parent=None):
          QtGui.QWidget.__init__(self, parent)
          self.Welcome = welcomeDialog()
          self.Welcome.setupUi(self)
          self.SourceTypeSelect = sourceTypeSelectDialog()
          self.SourceTypeConfirmation = sourceTypeConfirmationDialog()
          self.AcceptEula = acceptEulaDialog()
          self.ConfirmRequirements=confirmRequirementsDialog()
          self.SourceBinaryLocate=sourceBinaryLocateDialog()
          self.SourceBinaryProblems=sourceBinaryProblemsDialog()
          self.OutfileLocate=outfileLocateDialog()
          self.OutfileProbelms=outfileProblemsDialog()
          self.CollectionProgress=collectionProgressDialog()
          self.OutfileLocation=outfileLocationDialog

          #Connect up next/back/cancel etc.. buttons

  ???     self.Welcome.connect(self.Welcome.welcomeNext,
  QtCore.SIGNAL(clicked()),WelcomeNext)

  def WelcomeNext():
          #Code here to hide Welcome dialog and show SourceTypeSelect
  dialog

  if __name__ == __main__:
     app = QtGui.QApplication(sys.argv)
     myapp = StartQT4()
     myapp.show()
     sys.exit(app.exec_())

  My questions are, am I approaching this the right way, with a method
  per action per dialog to move through the dialogs, and just how do I
  setup the connections I need. I'm getting confused with scope etc. IE:
  if the connect is right, and WelcomeNext fires, how can it refer to
  myapp.SourceTypeSelect.show() or myapp.Welcome.hide()

  Any help much appreciated.

 Sounds like you are trying to build a wizard the hard way.

 Use Designer to create a QWizard with the contents of each of your dialogs
 as a QWizardPage.

 Phil- Hide quoted text -

 - Show quoted text -

Interesting idea. I shall take a look, but there is q fair amount of
work that needs to be done between dialogs, validation and other
thoings etc..  Would a QWizard help?


As well, I would like to understand the process of coding my own so I
can build other UI's also.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt signals/slots dialogs question

2010-06-07 Thread AlienBaby
My real aim here is to learn pyqt, so I would rather not the the
QWizard process until I understand myself whats going on behind the
scenes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt signals/slots dialogs question

2010-06-07 Thread AlienBaby
On Jun 7, 5:21 pm, AlienBaby matt.j.war...@gmail.com wrote:
 My real aim here is to learn pyqt, so I would rather not the the
 QWizard process until I understand myself whats going on behind the
 scenes.

Perhaps I posted to early, but a little more perserverance and I have
managed to unthaw the brain and move forward.  I've ended up with the
following. It does what I need, and now it's working I can think
around how to implement with a better approach;


from PyQt4 import QtCore, QtGui
from WELCOME import Ui_Dialog as welcomeDialog
from SOURCE_TYPE_SELECT import Ui_Dialog as sourceTypeSelectDialog
from SOURCE_TYPE_CONFIRMATION import Ui_Dialog as
sourceTypeConfirmationDialog

..snip

class WelcomeDialog(QtGui.QDialog):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui=welcomeDialog()
self.ui.setupUi(self)

class SourceTypeSelect(QtGui.QDialog):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui=sourceTypeSelectDialog()
self.ui.setupUi(self)

class SourceTypeConfirmation(QtGui.QDialog):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui=sourceTypeConfirmationDialog()
self.ui.setupUi(self)


def WelcomeNext():
welcome.hide()
sourceTypeSelect.show()
def WelcomeCancel():
sys.exit()


def SourceTypeSelectNext():
sourceTypeSelect.hide()
for widget in
sourceTypeSelect.ui.availableChoices.findChildren(QtGui.QWidget):
if widget.isChecked():
print widget.text()
 
sourceTypeConfirmation.ui.selectedSourceType.setText(widget.text())
sourceTypeConfirmation.show()
def SourceTypeSelectCancel():
sys.exit()


def SourceTypeConfirmationBack():
sourceTypeConfirmation.hide()
sourceTypeSelect.show()


if __name__ == __main__:
app = QtGui.QApplication(sys.argv)

#Instance dialogs and connect buttons
welcome=WelcomeDialog()
 
welcome.ui.welcomeNext.connect(welcome.ui.welcomeNext,QtCore.SIGNAL(clicked()),WelcomeNext)
 
welcome.ui.welcomeCancel.connect(welcome.ui.welcomeCancel,QtCore.SIGNAL(clicked()),WelcomeCancel)


sourceTypeSelect=SourceTypeSelect()
 
sourceTypeSelect.ui.sourceTypeSelectNext.connect(sourceTypeSelect.ui.sourceTypeSelectNext,QtCore.SIGNAL(clicked()),SourceTypeSelectNext)
 
sourceTypeSelect.ui.sourceTypeSelectCancel.connect(sourceTypeSelect.ui.sourceTypeSelectCancel,QtCore.SIGNAL(clicked()),SourceTypeSelectCancel)


sourceTypeConfirmation=SourceTypeConfirmation()
 
sourceTypeConfirmation.ui.sourceTypeConfirmationBack.connect(sourceTypeConfirmation.ui.sourceTypeConfirmationBack,QtCore.SIGNAL(clicked()),SourceTypeConfirmationBack)


welcome.show()
sys.exit(app.exec_())




-- 
http://mail.python.org/mailman/listinfo/python-list


default value in list comprehension

2010-04-19 Thread AlienBaby
Hi,

just a quick one,

Is it possible to achieve a default value in a list comprehension
where the if-clause is false?

Ie, something similar to:

[ a for a in b if something(a) else 'default' ]

the idea being that, rather than skip a value if the if-clause is
false, to place a default value at that position in the returned list
instead.

?

Thanks,


Matt.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default value in list comprehension

2010-04-19 Thread AlienBaby
On Apr 19, 1:23 pm, eb303 eric.brunel.pragma...@gmail.com wrote:
 On Apr 19, 2:20 pm, AlienBaby matt.j.war...@gmail.com wrote:





  Hi,

  just a quick one,

  Is it possible to achieve a default value in a list comprehension
  where the if-clause is false?

  Ie, something similar to:

  [ a for a in b if something(a) else 'default' ]

  the idea being that, rather than skip a value if the if-clause is
  false, to place a default value at that position in the returned list
  instead.

  ?

  Thanks,

  Matt.

 [a if something(a) else 'default' for a in b]

 HTH
  - Eric -- Hide quoted text -

 - Show quoted text -

Ahh.  Gotcha, thankyou :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simplify Python

2010-04-07 Thread AlienBaby
On 6 Apr, 20:04, ja1lbr3ak superheroco...@gmail.com wrote:
 I'm trying to teach myself Python, and so have been simplifying a
 calculator program that I wrote. The original was 77 lines for the
 same functionality. Problem is, I've hit a wall. Can anyone help?

 loop = input(Enter 1 for the calculator, 2 for the Fibonacci
 sequence, or something else to quit: )
 while loop  3 and loop  0:
     if loop == 1:
         print input(\nPut in an equation: )
     if loop == 2:
         a, b, n = 1, 1, (input(\nWhat Fibonacci number do you want to
 go to? ))
         while n  0:
             print a
             a, b, n = b, a+b, n-1
     loop = input(\nEnter 1 for the calculator, 2 for the Fibonacci
 sequence, or something else to quit: )


To replicate what you have above, I would do something like;

quit=False
while not quit:
choice=input('1 for calc, 2 for fib, any other to quit')
if choice==1:
print input('Enter expression: ')
elif choice==2:
a, b, n = 1, 1, input(\nWhat Fibonacci number do you want to 
go to?
)
 while n  0:
print a
a, b, n = b, a+b, n-1
else:
quit=True



?
-- 
http://mail.python.org/mailman/listinfo/python-list


Recommend Commercial graphing library

2010-04-06 Thread AlienBaby
Hi,

I'm on the hunt for a good quality commercially licensed graphing /
plotting library and wondered if anyone here had any recomendations.
The work to be done is less scientific, more presentational, (I'm not
going to be dealing with heatmaps / vectors etc.., just the usual
bar / line / bubble / radar / iceberg type graphs) so a good level of
control over how the final output looks would be a key point.

I'd be grateful for any suggestions / pointers to something useful,

thanks,

Matt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommend Commercial graphing library

2010-04-06 Thread AlienBaby
On Apr 6, 4:24 pm, Jean-Michel Pichavant jeanmic...@sequans.com
wrote:
 Pablo Recio Quijano wrote:
  Why must be commercial, when there is open and free alternatives? Like
  GNU Plot.

 Gnuplot is ugly. I'm using it because I don't care if it's ugly but it
 clearly lacks of look  feel for presentations, as requested by the OP.

 You havehttp://matplotlib.sourceforge.net/

 which is free and looks better than gnuplot. I'm not sure it's well
 suited for presentation though.

 JM

Hi,

The requirement for a commercial license comes down to being
restricted to not using any open source code. If it's an open source
license it can't be used in our context.

Until now I have actually been using matplotlib, but now that has to
change.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommend Commercial graphing library

2010-04-06 Thread AlienBaby
I am just looking at the PSF license now as it goes. It does appear
that we should be able to continue using matplotlib. - the
restrictions on open-source that have been imposed specifically state
it is fine to use the python language, and if matplotlib has the same
license I personally can't see any issue. However, the decision is not
mine.

The company I am with is unsure, and while they will pursue the
possible use of matplotlib with the PSF license, they would prefer I
continued to look into any commercially licensed libraries that could
be used.


...and as it goes, the first thing I fired back at them when I was
told 'no open source can be used' was basically 'What on earth are we
going to use to code it in...' and that the 'no open source'
restriciton as given was overly broad when you think about it.





-- 
http://mail.python.org/mailman/listinfo/python-list


Simple image manipulation question

2009-01-19 Thread AlienBaby
Hi,


Could anyone point me toward the right modules etc.. that would help
with;

loading an image file
rendering some text onto that image
saveing the image file


I've looked into Tkinter, but that seems to require working with
canvases etc.., but I do not need to actually display the image, just
render some text onto it and save it again.

PIL looked promising, but I couldn't see how to put text into the
image once loaded.


Any help much appreciated,

Thanks,

Matt.
--
http://mail.python.org/mailman/listinfo/python-list