Re: while True or while 1

2010-12-12 Thread Krister Svanlund
On Sun, Dec 12, 2010 at 3:14 PM, Max Countryman m...@me.com wrote:
 I'm sure this has been brought up many times, but a quick Googling didn't 
 yield the decisive results I was hoping for, so I apologize if this has 
 already been addressed in great detail somewhere else.

 I am wondering what the rationale is behind preferring while True over while 
 1? For me, it seems that using True provides more clarity, but is that the 
 only benefit? Is while 1 more prone to errors?

It's just silly to use 1 since it will evaluate to True either way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTMLWindow or HtmlWindow or perhaps HTMLwindo

2010-11-15 Thread Krister Svanlund

CapitalizedWords (or CapWords, or CamelCase -- so named because
  of the bumpy look of its letters[4]).  This is also sometimes known as
  StudlyCaps.

  Note: When using abbreviations in CapWords, capitalize all the letters
  of the abbreviation.  Thus HTTPServerError is better than
  HttpServerError.


On Mon, Nov 15, 2010 at 8:53 PM, Boštjan Mejak bostjan.me...@gmail.com wrote:
 Hello, I am wondering which of the 3 class names are prefered by PEP-8?

 class HTMLWindow(...)

 class HtmlWindow(...)

 class HTMLwindow(...)


 Thank you for your answer in advance.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: HTMLWindow or HtmlWindow or perhaps HTMLwindo

2010-11-15 Thread Krister Svanlund
On Mon, Nov 15, 2010 at 9:09 PM, Ben James bmja...@gmail.com wrote:
 On 15/11/2010 19:53, Boštjan Mejak wrote:

 Hello, I am wondering which of the 3 class names are prefered by PEP-8?

 class HTMLWindow(...)

 class HtmlWindow(...)

 class HTMLwindow(...)


 Thank you for your answer in advance.

 PEP 8 says:

    Note: When using abbreviations in CapWords, capitalize all the
    letters of the abbreviation.  Thus HTTPServerError is better than
    HttpServerError.

 So, to apply that to your example, PEP 8 recommends HTMLWindow.
 --
 http://mail.python.org/mailman/listinfo/python-list


Yeah, since HTML is an abbreviation it's the exact recommendation to use... :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Krister Svanlund
On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro msa...@gmail.com wrote:
 Hey Everyone,
 Just curious - I'm working on a program which includes a calculation of a
 circle, and I found myself trying to use pi*radius^2, and getting errors
 that data types float and int are unsupported for ^. Now, I realized I was
 making the mistake of using '^' instead of **. I've corrected this and its
 now working. However, what exactly does ^ do? I know its used in regular
 expressions but I can't seem to find anything about using it as an operator.
 Sadly my google foo is failing since the character gets filtered out.

It's a binary operator i think... something like xor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How i can get data from an image

2010-10-26 Thread Krister Svanlund
You should check out OpenCV.

On Tue, Oct 26, 2010 at 8:53 PM, Kechagias Apostolos
pasxal.an...@gmail.com wrote:
 Hello there.
 I ve been using python a lot lately for my school in order to make small
 gui(wxpython) apps.
 Today a teacher came up with an interesting project.
 The idea is that he gives you a series of photos with some objects inside.
 For example a photo could contain two black circles in a white background.
 The question is how can i find a circle in a given image?
 When i find the circles how can i draw a line between them in order to
 create a connection?
 I know that this may need pattern recognition.
 What i want you to tell me is what things i will need in order to make this
 thing possible with python.
 My idea is to use use PIL in order to find the circles in the image.
 Then i will import this image to wxpython canvas and i will draw a line
 between their centers.
 Is that possible?
 I really need some help here.
 --
 http://mail.python.org/mailman/listinfo/python-list


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


Re: C++ vs. Python Was: Re: help!!!

2010-10-06 Thread Krister Svanlund
On Wed, Oct 6, 2010 at 12:16 PM, Hans-Peter Jansen h...@urpla.net wrote:
 On Wednesday 06 October 2010, 06:28:51 Dennis Lee Bieber wrote:
 On Tue, 05 Oct 2010 23:54:00 -0400, fkr...@aboutrafi.net23.net

 declaimed the following in gmane.comp.python.general:
  plz can u convert this cpp file into python i need that badly as soon
  as possible... I am new to python. I just wanna learn it

       Step one... DON'T TRY TO PORT C++ to Python... the object models are
 quite different.

 I do this all the time without any adverse effects (other than being glad to
 only rarely having the need of doing it the other way around ;-)).

I have on occasion translated a few algorithms from python to c++ and
only needed to spend minimal time pythonize the code. Generally I
believe that porting from python to c++ and the other way around can
be done pretty nicely but you always have to take care to restructure
what has to be restructured.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3D cube navigation

2010-09-10 Thread Krister Svanlund
On Fri, Sep 10, 2010 at 9:10 PM, sahilsk sonukr...@gmail.com wrote:
 hi, i need to make a 3d cube as a navigation menu.. each face having
 separate  button .. or effect.
 any idea,  how can i make one such 3D figures with functionality of
 mouse events?

In what environment, what toolkit, for what purpose?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine if a Python script is being run right after startup on Windows

2010-09-07 Thread Krister Svanlund
On Tue, Sep 7, 2010 at 11:43 AM, Dennis Verdonschot thos...@gmail.com wrote:
 Hi Ryan,

 Maybe I'm missing something, but wouldn't creating a shortcut and
 putting that shortcut in your Start - Programs - Startup section of
 the Windows menu not work for this program? Or if really needed you
 can edit the start-up programs in the registry.

 If you add some logging ability to your program you can verify it has
 been run and you can still use commandline arguments by changing the
 shortcut.

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


I would recommend using a commandline switch (look at sys.argv in
documentation) and just start the script with something like
python script.py --change-wallpaper
or maybe require a switch for getting to the GUI...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stackless Python and EVE Online

2010-08-31 Thread Krister Svanlund
On Tue, Aug 31, 2010 at 5:10 PM, Benjamin Kaplan
benjamin.kap...@case.edu wrote:
 On Tuesday, August 31, 2010, Roman Sokolyuk romsok.t...@gmail.com wrote:
 Hi,

 I am new to Python and I wanted to understand something...
 The EVE Online Client is build using Stackless Python
 So when I install the client on my machine, how doe sit get run if I do not 
 have Python installed?

 We call it freezing the program. There are several tools that do
 this with py2exe being the most popular. These tools create an
 executable that includes a bundled python interpreter along with all
 the scripts and modules needed to run the program.
 Thanks.
 --
 http://mail.python.org/mailman/listinfo/python-list


I'm not sure but I do believe it is mainly the servers that are
written in stackless...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating addon system

2010-05-21 Thread Krister Svanlund
On Fri, May 21, 2010 at 5:50 PM, timo verbeek timoverbee...@gmail.com wrote:
 What is the easiest way in python to create a addon system?
 I found to easy ways:
 * using a import system like this:
       for striper in stripers:
        if striper[enabled]:
            exec(from strip import %s as _x%striper[striper])
            string = _x.start(string)
 * using exec
       for striper in stripers:
        if striper[enabled]:
            use=open(stripper)
            exec(use)

 Do you now is the best way?
 --
 http://mail.python.org/mailman/listinfo/python-list


Check this one out: http://docs.python.org/library/functions.html#__import__
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables for python applications

2010-05-16 Thread Krister Svanlund
On Sun, May 16, 2010 at 7:50 PM, AON LAZIO aonla...@gmail.com wrote:
 Hi,
    How can I set up global variables for the entire python applications?
 Like I can call and set this variables in any .py files.
    Think of it as a global variable in a single .py file but this is for the
 entire application.
    Thanks

 --
 Aonlazio
 'Peace is always the way.' NW

First: Do NOT use global variables, it is bad practice and will
eventually give you loads of s**t.

But if you want to create global variables in python I do believe it
is possible to specify them in a .py file and then simply import it as
a module in your application. If you change one value in a module the
change will be available in all places you imported that module in.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help in python plug-in development

2010-04-28 Thread Krister Svanlund
On Wed, Apr 28, 2010 at 12:21 PM, Suraj Sakhare suraj.0...@gmail.com wrote:
 Hi, I am new to python. I am using python 2.6. I have gone through the
 basic python and now I am trying to develop some plugin for maya 2009
 through python. So, for that I would need helping hand.

You would have to ask questions for that... just so you know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any modules having a function to partition a list by predicate provided?

2010-04-19 Thread Krister Svanlund
On Tue, Apr 20, 2010 at 3:40 AM, segunai osk@gmail.com wrote:
 On 4월20일, 오전10시16분, Chris Rebert c...@rebertia.com wrote:
 On Mon, Apr 19, 2010 at 6:00 PM, knifenomad knifeno...@gmail.com wrote:
  i know it's not very hard to get that solution.
  just by implementing simple function like below.

   def partition(target, predicate):
 
 split a list into two partitions with a predicate
  provided.
 any better ideas? :)
 
 true = []
 false= []
 for item in target:
 if predicates(item):
 true.append(item)
 else:
 false.append(item)
 return true, false

  but i wonder if there's another way to do this with standard libraries
  or .. built-ins.
  if it's not, i'd like the list objects to have partition method like
  string module has.

 (A) str.partition() has a /completely/ different meaning from your 
 partition()
 (B) You'd probably have better luck getting it added to the itertools
 module since the concept is applicable to all iterables.
 [http://docs.python.org/library/itertools.html]

 Cheers,
 Chris
 --http://blog.rebertia.com

 yep, my mistake. i shouldn't have compared it to string's partition().
 i just wanted that convenience string.partition() has as a built-in.
 anyway, thanks for itertools. :)
 --
 http://mail.python.org/mailman/listinfo/python-list


The way I would do it is probably apply filter to the list:
 def f(x): return x % 2 != 0 and x % 3 != 0
...
 filter(f, range(2, 25))
[5, 7, 11, 13, 17, 19, 23]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Learning Environment

2010-04-17 Thread Krister Svanlund
On Sat, Apr 17, 2010 at 6:32 PM, Vijay Shanker Dubey
vijay.s...@gmail.com wrote:
 Hi,
 My Linux box is ubuntu system. I want to create a development environment on
 my system for python programing language. I got to see there are two
 versions of python language
 1. python 2.5.6
 2. python 3.1.2
 To find out what version i look in to my /usr/bin folder. There are many
 entries for python command
 - python
 - python2
 - python2.5
 - python2.6
 - python3
 - python3.1
 what does this mean? I am able to run run my first program with all these
 command. should i remove all these and have the latest one? I am confused
 about these finding. Is this okay to have these all?

 Regards,
 Vijay Shanker Dubey


python is symlinked to one of the 2.5, 2.6 or 3.1... most probably
2.6. The python2 is symlink to one of 2.5 or 2.6 and python3 is
symlinked to python3.1. It's a clever way to be able to specify what
version is needed for a script.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Learning Environment

2010-04-17 Thread Krister Svanlund
On Sat, Apr 17, 2010 at 7:06 PM, Vijay Shanker Dubey
vijay.s...@gmail.com wrote:
 Yes you are right about symlink thing.
 So what should I do for a clever developer environment?
 Should I change that python link to python3 or python3.1?

 Regards,
 Vijay Shanker Dubey


It all depends on what you want to do. I would say that you shouldn't
change your python link at all, if you want to run a python script
using 3.1 just call the script using python3 as an interpreter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run python without python

2010-04-01 Thread Krister Svanlund
On Fri, Apr 2, 2010 at 1:36 AM, Spencer infotech...@fairpoint.net wrote:
 Is there a way to developing a script on linux and give it
 to someone on microsoft, so that they could run it on microsoft
 without installing python?

 Wayne

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


Short answer: No.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Meaning of monkey

2010-03-29 Thread Krister Svanlund
On Mon, Mar 29, 2010 at 3:09 PM, djc slais-...@ucl.ac.uk wrote:
 Mensanator wrote:
 On Mar 26, 2:44 pm, Phlip phlip2...@gmail.com wrote:
 On Mar 26, 6:14 am, Luis M. González luis...@gmail.com wrote:

 Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, Jägermonkey,
 Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc...
 Monkeys everywhere.
 Sorry for the off topic question, but what does monkey mean in a
 nerdy-geek context??
 Luis
 Better at typing than thinking.

 Really? I thought it was more of a reference to Eddington, i.e., given
 enough time even a monkey can type out a program.


 Precisely, given infinite typing and zero thinking...

 Note also the expression 'talk to the organ  grinder not the monkey'

 and 'a trained monkey could do it'

 and then there are monkey wrenches, and monkey bikes...

 and never call the Librarian a monkey


The monkeys comes from different places... for example:
The term monkey patch was first used as guerrilla patch, [...], which
was referred to as the patches engaging in battle with each other.
Since the word guerrilla and gorilla are near-homophones, people
started using the incorrect term gorilla patch instead of guerrilla
patch. When a developer then created a guerrilla patch they tried very
hard to avoid any battles that may ensue due to the patch and the term
monkey patch was coined to make the patch sound less forceful.

And then there is, as said, monkey wrenches which is utility tools.
Codemonkeys, i believe, comes from the infinite monkeys theory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sys.path when embedding Python3 in C

2010-03-23 Thread Krister Svanlund
On Tue, Mar 23, 2010 at 8:07 AM, Gabriel Genellina
gagsl-...@yahoo.com.ar wrote:
 En Mon, 22 Mar 2010 18:19:49 -0300, Krister Svanlund
 krister.svanl...@gmail.com escribió:

 Hi, I've recently begun experimenting with embedding python and i got
 a small problem.

 The following line here is the ugly-hack I had to do to make it work,
 nothing else I know of makes it possible to import modules from
 startup directory. So my question is: Is there a prettier way to do
 this?

 The startup directory is not included in the module search path - neither in
 your embedded version, nor in the standard interpreter (it's only included
 when running in interactive mode).

 PyRun_SimpleString(import sys\nsys.path.append(\\));

 If you really want the current directory in sys.path, use the getcwd
 function to obtain it. But make sure this is what you want - the directory
 containing the executable might be a better choice (at least more
 predictable).
 Note that Python already provides lots of ways to add directories to
 sys.path (the default search path (see site.py), per-user site directories
 (see PEP370), .pth files, the PYTHONPATH and PYTHONHOME environment
 variables, the Windows registry, other ways I forgot...) So I'd ask why do
 you want to add a non-standard one.

 In C code, you can alter the initial search path by setting
  Py_SetProgramName and Py_SetPythonHome. And you may even completely replace
 getpathp.c source file with your own.

 --
 Gabriel Genellina

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


The thing is that I want the application to be able to import modules
I've written, but yeah, the applications directory is what I want
rather than the cwd. I have tried Py_SetProgramName but haven't gotten
it to work or cause any change at all to the import behaviour. Could
you possibly provide som sort of example?
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with sys.path when embedding Python3 in C

2010-03-22 Thread Krister Svanlund
Hi, I've recently begun experimenting with embedding python and i got
a small problem.
This is my current testing code (basically all from python docs):

 int main(int argc, char *argv[])

 {

 PyObject *pModuleName, *pTestModule, *pTestFunc, *pTestResult, *pTestArgs;

 PyImport_AppendInittab(node, PyInit_node);

 Py_Initialize();

The following line here is the ugly-hack I had to do to make it work,
nothing else I know of makes it possible to import modules from
startup directory. So my question is: Is there a prettier way to do
this?

 PyRun_SimpleString(import sys\nsys.path.append(\\));

 PyRun_SimpleString(import sys\nprint(sys.path));

 pModuleName = PyUnicode_FromString(stuff);

 pTestModule = PyImport_Import(pModuleName);

 Py_DECREF(pModuleName);

 if (pTestModule != NULL)

 { ...

The whole code is here: http://pastebin.com/805BSY8f
You only need a file in the same directory called stuff.py containing
a function def for a function called do_stuff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [python3]

2010-03-19 Thread Krister Svanlund
On Fri, Mar 19, 2010 at 6:42 PM, Kevin Adams incensedp...@gmail.com wrote:
 Greetings!

 Please forgive me if im posting this to the wrong group.

 I'm new to Python, learning Python3 from the O'rielly Learning
 Python book.  Reading
 about operator overloading, specifically __getitem__.   I put together
 a small bit of code to
 do some experimenting and threw in a timer so i can see it do its
 thing.  For some reason
 the time.sleep(x) function doesnt work when my print function includes
 end=''.

 Thanks in advance for any help.


 ---code---

 class TestClass():
    def __init__(self):
        self.data = I was far from home and the spell of the eastern
 sea was upon me.

    def __getitem__(self,i):
        return self.data[i]


 import time

 if __name__ == __main__:

    me = TestClass()
    for x in me:
        print(x,end='')  #if i remove the 'end='''  it performs as i'd
 expect
        time.sleep(int(2))

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


I'm guessing wildly here but I think you have to flush the output.
Can't remember how right now but it won't take much googling for it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will Python go mainstream like Java?

2010-02-23 Thread Krister Svanlund
On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk f...@mauve.rahul.net wrote:
 You mean it's not?

 --
        -Ed Falk, f...@despams.r.us.com
        http://thespamdiaries.blogspot.com/

Javas popularity was very much a product of its time. It was something
new and exciting and people got a bit too excited maybe, Python just
does the same thing but better really, therefor it will not become as
popular.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's Going on between Python and win7?

2010-02-22 Thread Krister Svanlund
On Mon, Feb 22, 2010 at 4:22 PM, W. eWatson wolftra...@invalid.com wrote:
 Last night I copied a program from folder A to folder B. It inspects the
 contents of files in a folder. When I ran it in B, it gave the results for
 A! Out of frustration I changed the name in A, and fired up the program in
 B. Win7 went into search mode for the file. I looked at properties for the B
 program, and it was clearly pointing to folder A.

 Anyone have this happen to them?

 Another anomaly. I have the files track.py and trackstudy.py in the same
 folder along with 100 or so other py and txt data files. When I did a search
 from the folder window in the upper right corner, search only found one of
 the two. I called HP tech support about it, and they could see it for
 themselves via remote control. They had no idea, but agreed to  contact MS.
 In this case, I noted that this search box has some sort of filter
 associated with it. Possibly, in my early stages of learning to navigate in
 Win7, I accidentally set the filter.

 Comments?

I can't really see the python related problem here...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When will Python go mainstream like Java?

2010-02-22 Thread Krister Svanlund
On Mon, Feb 22, 2010 at 10:56 PM, AON LAZIO aonla...@gmail.com wrote:
 That will be superb

 --
 Passion is my style

And when will insert random band be as famous as the beatles?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if not global -- then what?

2010-02-20 Thread Krister Svanlund
On Sat, Feb 20, 2010 at 8:25 PM, egasimus fallenbl...@gmail.com wrote:
 Hi, newbie here. I've read on using the 'global' keyword being
 discouraged; then what is the preferred way to have something, for
 example a class containing program settings, accessible from
 everywhere, in a program spanning multiple files?
 --
 http://mail.python.org/mailman/listinfo/python-list


There is probably a smarter way but I would recommend passing a
settings object around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to continue after an exception ?

2010-02-20 Thread Krister Svanlund
On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki stef.mien...@gmail.com wrote:
 hello,

 I would like my program to continue on the next line after an uncaught
 exception,
 is that possible ?

 thanks
 Stef Mientki


Yes, you catch the exception and do nothing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Python code on another computer

2010-02-19 Thread Krister Svanlund
On Fri, Feb 19, 2010 at 4:52 PM, SiWi wimmersi...@googlemail.com wrote:
 Hello community,
 I googled for an answer of the following problem, but I couldn't find
 anything.
 I've got a netbook and my fast workstation compter, which I usually
 use for developing.
 But I'd also like to take my netbook around the house and to develop
 Python programms on it.
 The problem is that naturally a netbook is not the fastest computer
 you could find.

 So I wondered if it was possible to send the Python code I'm
 developing on the netbook to the workstation pc via wlan, let the
 script execute on the workstation pc and write the output back on the
 netbook.

 Is there any possibilty to achieve that goal?
 --
 http://mail.python.org/mailman/listinfo/python-list


I recommend setting up a SSH server on your stationary and run
something like emacs. It's how I'm doing it anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about getmtime

2010-02-19 Thread Krister Svanlund
On Fri, Feb 19, 2010 at 5:05 PM, Brandon btaylordes...@gmail.com wrote:
 Hi everyone,

 Does copying or moving a file affect the return value of
 os.path.getmtime(path)?

 Thank you,
 Brandon

Wouldn't it be easier to make a script and see for yourself then to
write a mail about it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Krister Svanlund
On Wed, Feb 10, 2010 at 2:59 PM, Muhammad Alkarouri
malkaro...@gmail.com wrote:
 Hi everyone,

 What is the simplest way to access the attributes of a function from
 inside it, other than using its explicit name?
 In a function like f below:

 def f(*args):
    f.args = args
    print args

 is there any other way?
 I am guessing the next question will be: should I really care? It just
 feels like there should be a way, but I am not able to verbalise a
 valid one at the moment, sorry.

 Regards,

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


This sounds like something you shouldn't be doing. You should probably
use a class instead.

(Sending again to get it on the list _)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with a program

2010-01-28 Thread Krister Svanlund
On Thu, Jan 28, 2010 at 4:07 PM, evilweasel
karthikramaswam...@gmail.com wrote:
 Hi folks,

 I am a newbie to python, and I would be grateful if someone could
 point out the mistake in my program. Basically, I have a huge text
 file similar to the format below:

 AGACTCGAGTGCGCGGA   0
 AGATAAGCTAATTAAGCTACTGG     0
 AGATAAGCTAATTAAGCTACTGGGTT   1
 AGCTCACAATAT     1
 AGGTCGCCTGACGGCTGC  0

 The text is nothing but DNA sequences, and there is a number next to
 it. What I will have to do is, ignore those lines that have 0 in it,
 and print all other lines (excluding the number) in a new text file
 (in a particular format called as FASTA format). This is the program I
 wrote for that:

 seq1 = []
 list1 = []
 lister = []
 listers = []
 listers1 = []
 a = []
 d = []
 i = 0
 j = 0
 num = 0

 file1 = open(sys.argv[1], 'r')
 for line in file1:
    if not line.startswith('\n'):
        seq1 = line.split()
        if len(seq1) == 0:
            continue

        a = seq1[0]
        list1.append(a)

        d = seq1[1]
        lister.append(d)


 b = len(lister)
 for j in range(0, b):
    if lister[j] == 0:
        listers.append(j)
    else:
        listers1.append(j)


 print listers1
 resultsfile = open(sequences1.txt, 'w')
 for i in listers1:
    resultsfile.write('\nseq' + str(i) + '\n' + list1[i] + '\n')

 But this isn't working. I am not able to find the bug in this. I would
 be thankful if someone could point it out. Thanks in advance!

 Cheers!

I'm not totaly sure what you want to do but try this (python2.6+):

newlines = []

with open(sys.argv[1], 'r') as f:
text = f.read();
for line in text.splitlines():
if not line.strip() and line.strip().endswith('1'):
newlines.append('seq'+line)

with open(sys.argv[2], 'w') as f:
f.write('\n'.join(newlines))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with a program

2010-01-28 Thread Krister Svanlund
On Thu, Jan 28, 2010 at 4:28 PM, Krister Svanlund
krister.svanl...@gmail.com wrote:
 On Thu, Jan 28, 2010 at 4:07 PM, evilweasel
 karthikramaswam...@gmail.com wrote:
 Hi folks,

 I am a newbie to python, and I would be grateful if someone could
 point out the mistake in my program. Basically, I have a huge text
 file similar to the format below:

 AGACTCGAGTGCGCGGA   0
 AGATAAGCTAATTAAGCTACTGG     0
 AGATAAGCTAATTAAGCTACTGGGTT   1
 AGCTCACAATAT     1
 AGGTCGCCTGACGGCTGC  0

 The text is nothing but DNA sequences, and there is a number next to
 it. What I will have to do is, ignore those lines that have 0 in it,
 and print all other lines (excluding the number) in a new text file
 (in a particular format called as FASTA format). This is the program I
 wrote for that:

 seq1 = []
 list1 = []
 lister = []
 listers = []
 listers1 = []
 a = []
 d = []
 i = 0
 j = 0
 num = 0

 file1 = open(sys.argv[1], 'r')
 for line in file1:
    if not line.startswith('\n'):
        seq1 = line.split()
        if len(seq1) == 0:
            continue

        a = seq1[0]
        list1.append(a)

        d = seq1[1]
        lister.append(d)


 b = len(lister)
 for j in range(0, b):
    if lister[j] == 0:
        listers.append(j)
    else:
        listers1.append(j)


 print listers1
 resultsfile = open(sequences1.txt, 'w')
 for i in listers1:
    resultsfile.write('\nseq' + str(i) + '\n' + list1[i] + '\n')

 But this isn't working. I am not able to find the bug in this. I would
 be thankful if someone could point it out. Thanks in advance!

 Cheers!

 I'm not totaly sure what you want to do but try this (python2.6+):

 newlines = []

 with open(sys.argv[1], 'r') as f:
    text = f.read();
    for line in text.splitlines():
        if not line.strip() and line.strip().endswith('1'):
            newlines.append('seq'+line.strip()[:-1].strip())

 with open(sys.argv[2], 'w') as f:
    f.write('\n'.join(newlines))


Gah, made some errors
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with a program

2010-01-28 Thread Krister Svanlund
On Thu, Jan 28, 2010 at 4:31 PM, Krister Svanlund
krister.svanl...@gmail.com wrote:
 On Thu, Jan 28, 2010 at 4:28 PM, Krister Svanlund
 krister.svanl...@gmail.com wrote:
 On Thu, Jan 28, 2010 at 4:07 PM, evilweasel
 karthikramaswam...@gmail.com wrote:
 Hi folks,

 I am a newbie to python, and I would be grateful if someone could
 point out the mistake in my program. Basically, I have a huge text
 file similar to the format below:

 AGACTCGAGTGCGCGGA   0
 AGATAAGCTAATTAAGCTACTGG     0
 AGATAAGCTAATTAAGCTACTGGGTT   1
 AGCTCACAATAT     1
 AGGTCGCCTGACGGCTGC  0

 The text is nothing but DNA sequences, and there is a number next to
 it. What I will have to do is, ignore those lines that have 0 in it,
 and print all other lines (excluding the number) in a new text file
 (in a particular format called as FASTA format). This is the program I
 wrote for that:

 seq1 = []
 list1 = []
 lister = []
 listers = []
 listers1 = []
 a = []
 d = []
 i = 0
 j = 0
 num = 0

 file1 = open(sys.argv[1], 'r')
 for line in file1:
    if not line.startswith('\n'):
        seq1 = line.split()
        if len(seq1) == 0:
            continue

        a = seq1[0]
        list1.append(a)

        d = seq1[1]
        lister.append(d)


 b = len(lister)
 for j in range(0, b):
    if lister[j] == 0:
        listers.append(j)
    else:
        listers1.append(j)


 print listers1
 resultsfile = open(sequences1.txt, 'w')
 for i in listers1:
    resultsfile.write('\nseq' + str(i) + '\n' + list1[i] + '\n')

 But this isn't working. I am not able to find the bug in this. I would
 be thankful if someone could point it out. Thanks in advance!

 Cheers!

I'm trying this again:

newlines = []

with open(sys.argv[1], 'r') as f:
   text = f.read();
   for line in (l.strip() for l in text.splitlines()):
       if line:
           line_elem = line.split()
           if len(line_elem) == 2 and line_elem[1] == '1':
               newlines.append('seq'+line_elem[0])

with open(sys.argv[2], 'w') as f:
   f.write('\n'.join(newlines))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default path for files

2010-01-24 Thread Krister Svanlund
On Sun, Jan 24, 2010 at 4:08 PM, Rotwang sg...@hotmail.co.uk wrote:
 Hi all, can anybody tell me whether there's a way to change the default
 location for files to be opened by open()? I'd like to be able to create
 files somewhere other than my Python folder without having to write the full
 path in the filename every time. Sorry if this is a stupid question, I don't
 know much about programming.

Check out http://docs.python.org/library/os.html and the function
chdir it is what you are looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python not good enough?

2010-01-12 Thread Krister Svanlund
Every language has it uses and Google obviously thought that it would
take more resources to get Python to the level they need it than to
start using Go.

Python is great for alot of things but it's not perfect for anything.

On Tue, Jan 12, 2010 at 4:09 PM, ikuta liu ikut...@gmail.com wrote:
 I'm a little confused.
 Is python not good enough?
 for google, enhance python performance is the good way better then
 choose build Go language?

 Go language try to merge low level, hight level and browser language.

 Those I'd like to see it on python..
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Absolute beginner

2009-12-30 Thread Krister Svanlund
In Python 3 the syntax for print has changed to print() so just put
braces around the string and you'r good to go!

On Wed, Dec 30, 2009 at 12:48 PM,  lucbo...@hotmail.com wrote:
 Hi there,
 I installed python 3.1 on Windows Vista PC.
 Am an absolute beginner with Python.
 This is my problem :

 In Idle :

 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit
 (Intel)] on win32
 Type copyright, credits or license() for more information.
 print Hello
 SyntaxError: invalid syntax (pyshell#0, line 1)

 At a dos-prompt :

 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit
 (Intel)] on
 win32
 Type help, copyright, credits or license for more information.
 print Hello
  File stdin, line 1
    print Hello
                ^
 SyntaxError: invalid syntax


 Looks stupid, probably is, but I cannot figure it out.

 Thanks for any help !

 Lucky

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

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


Re: list comprehension problem

2009-11-02 Thread Krister Svanlund
On Mon, Nov 2, 2009 at 10:11 PM, Aahz a...@pythoncraft.com wrote:
 In article 
 7589e0a1-98b2-4df4-bc76-5d4c10194...@f20g2000prn.googlegroups.com,
 Falcolas  garri...@gmail.com wrote:

I'd also recommend trying the following filter, since it is identical
to what you're trying to do, and will probably catch some additional
edge cases without any additional effort from you.

[s.strip() for s in hosts if s.strip()]

 This breaks if s might be None

If you don't want Nones in your list just make a check for it...
[s.strip() for s in hosts if s is not None and s.strip()]
-- 
http://mail.python.org/mailman/listinfo/python-list