delineating by comma where commas inside quotation marks don't count

2007-10-24 Thread Junior
I want to open a text file for reading and delineate it by comma.  I also 
want any data
surrounded by quotation marks that has a comma in it, not to count the 
commas inside the
quotation marks

if the file testfile.txt contains the following;

5,Tuesday,"May is a spring month",Father's Day
1,Saturday,"June,July and August",Independance Day


and I write the following program

fname = open('testfile.txt', 'r')
ct=1
while ct != 3:
rd=(fname.readline())
filedata=rd.split(',')
print "var2=",filedata[2]
ct +=1

fname.close

filedata[2] will = "May is a spring month"; on the first pass and

filedata[2] will = "June;  on the second pass

How do I get filedata[2] to = "June,July and August" on the second pass

and filedata[3] to = Independance Day


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


Re: delineating by comma where commas inside quotation marks don't count

2007-10-26 Thread Junior

"Dan Bishop" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Oct 24, 8:56 pm, "Junior" <[EMAIL PROTECTED]> wrote:
>> I want to open a text file for reading and delineate it by comma.  I also
>> want any data
>> surrounded by quotation marks that has a comma in it, not to count the
>> commas inside the
>> quotation marks
>
> Use the csv module.
Thanks for the help! I used the csv module to write this;

import csv
reader = csv.reader(open('testfile.txt', "rb"))
for row in reader:
print "var2= ", row[2]


The reason I didn't use the csv module is because I read this book to learn
Python,

Python Programming for the Absolute Beginner, Second Edition (For the
Absolute Beginner)
by Michael Dawson (Author),

and it did not mention the csv module it just explained how to import
modules. I also read

the tutorial that comes with python but it ends with the History and License
section.

Can you recommend a book that explains the most used modules?



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


Observer pattern implementation in Python based on jQuery

2016-01-14 Thread fernando junior
Hi,

I made an observer/pubsub pattern implementation in Python based on jQuery. 
It's available in https://github.com/fernandojunior/python-pattern-observer.

Take a look! :)
Fernando Felix
https://br.linkedin.com/in/fernandofnjr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "x == None" vs "x is None"

2016-01-19 Thread fernando junior

> I have seen at several places "x == None" and "x is None" within
> if-statements.
> What is the difference? 
> Which term should I prefer and why?
> 
> 
> -- 
> Ullrich Horlacher  Server und Virtualisierung
> Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
> Universitaet Stuttgart Tel:++49-711-68565868
> Allmandring 30aFax:++49-711-682357
> 70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/

In this case, the Style Guide for Python Code [1] recommends use "is or is not, 
never the equality operators" [2].

If you use the pep8 tool [3] to check your code, the error code that will be 
raised is E711 [4].

[1] https://www.python.org/dev/peps/pep-0008/
[2] https://www.python.org/dev/peps/pep-0008/#programming-recommendations
[3] http://pep8.readthedocs.org/en/latest/intro.html
[4] http://pep8.readthedocs.org/en/latest/intro.html#error-codes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class hierarchy problem

2013-08-06 Thread Joe Junior
On Tue, Aug 6, 2013 at 12:36 PM, BrJohan  wrote:
> On 06/08/2013 16:02, Chris Angelico wrote:
>
>>> My classhierarchy is like a multilevel tree where each non-leaf node
>>> (class)
>>> is given knowledge about its nearest subclasses and their 'capacities'.
>>>
>>> So, my idea is to let the 'upper' class recursively choose which of its
>>> nearest subclasses is the 'correct' one, until approaching a 'leaf' class
>>> from which the instance should be created. And, given my knowledge that a
>>> solution along the lines of this idea has been designed and was working,
>>> I'm
>>> still hopeful ... (or I'll have to investigate all those old backup-DVDs)
>>
>>
>> [ responding on-list - I hope it was mere oversight that had this come
>> privately to me alone ]
>>
>> This is code smell; this recursive search for the "right" class seems
>> likely to be wrong. Can you have the classes perhaps register
>> themselves in some way? On what basis is a superclass to determine
>> that one of its subclasses should handle this request?
>>
>> ChrisA
>>
>
>
> Consider a botanical classification system (somewhat analogous to my
> 'problem' as it effectively is related to classification of entities):
>
> A Domain should know about its Kingdoms,
> a Kingdom should know about its Phylums,
> ...
> a Genus should know about its Species.
>
> Of course it is possible to implement such a decision tree as a 'factory'.
> However, I would rather prefer to encapsulate those decisions at the class
> level where they 'belong'.
>
> BrJohan
> --

I think it's a "has a" vs a "is a" problem. A Domain has a Kingdom, a Kingdom is
not a Domain, so it shouldn't actually inherit Domain. In this case
you should use
composition instead of inheritance.

When you say that a A Domain should know about it's Kingdons note that you're
talking about a specific Domain and it's specific Kingdons, which
means, a Domain
instance and various Kingdom instances.

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


Interface and duck typing woes

2013-08-28 Thread Joe Junior
While designing a simple library, I found myself asking a
philosophical question: to check or not to check the parameter's
interface?

I think that, considering it is Python, the usual answer would be
"no", but here is the situation that got me thinking:

class Flock:

def __init__(self):
self.ducks= []

def do_stuff(self):
for duck in self.ducks:
duck.quack()

class Duck:

def quack(self):
#quack-quack
pass

f = Flock()
d = Duck()
f.ducks.append(d)
f.do_stuff()

Ok, no big deal there, the problem is if the user forgets to implement
the quack() method. The stack trace would complain that "duck.quack()"
is wrong, but that can happen hundreds of lines after the user
actually added the object to the Flock, and it can be hard to find out
what is happening and which object is wrong.

Of course I don't want to check isistance(), I like duck typing, but
should I check if hasattr() and callable() before adding to the
container? What is the pythonic way to deal with it? Am I worrying too
much ;-)?

Thanks,

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


Re: Interface and duck typing woes

2013-08-29 Thread Joe Junior
Well, the main reason for me asking this question here was because of
the Java/C#/Whatever developer in me craving for an Interface for the
container's items, and I noticed that I'm not alone in this. But I was
actually expecting the "We're all consenting adults, here", I guess I
just needed the confirmation :-)

Another reason for this question is that I read some people saying
they wouldn't use python for large projects, and they always point at
the lack of Interfaces as a concern. I actually disagree, but I can
see their point. What do you think?

@Nobody
>> Of course I don't want to check isistance(), I like duck typing, but
>> should I check if hasattr() and callable() before adding to the container?
>That won't tell you if the object has a quack() method but with
>incompatible semantics (e.g. wrong number or types of arguments).

Yeah, didn't think about that, it's kinda swimming upstream!
Definitely it is more hassle than it is worth.

@ChrisA
>Do you believe that you can write code to catch every bug you might
>make? If so, you are naive and probably haven't spent much time
>programming yet :) And if not, then you must acknowledge that bugs
>WILL happen; therefore you will need to cope with them after the
>event. So rather than trying to prevent them all, just improve your
>means of coping, and you'll accomplish the same end with much less
>trouble.

Oh, no! I'm not that presumptuous (or naive)! But what do you mean by
"improve means of coping"? Do you know any article on the subject you
could point me?

@Steven
>> Of course I don't want to check isistance(), I like duck typing, but
>> should I check if hasattr() and callable() before adding to the
>> container? What is the pythonic way to deal with it? Am I worrying too
>> much ;-)?

>Yes :-)

Well, thanks! :-) And thanks for the article.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interface and duck typing woes

2013-08-29 Thread Joe Junior
On 29 August 2013 10:07, Chris Angelico  wrote:
> Hmm. l don't know of any good articles off-hand. But what I'm talking
> about is simply developing the skill of reading exceptions, plus a few
> simple things like knowing where it's appropriate to catch-and-log;
> sometimes, what that means is actually writing some code to (for
> example) email you whenever there's an exception, but more likely it
> means writing no code at all, and just looking at STDERR of your live
> usage. Works really well for >95% of Python scripts.
>
> The most important thing to consider is: What happens if my code
> doesn't run all the way through? Is it safe for this to run part way,
> then bomb with an exception? For many scripts, it's pretty easy: fix
> the problem and rerun the script, and it'll completely rewrite its
> output file. For others, this is a good reason for putting all your
> "real data" into a transactional database - you begin a transaction at
> the top, don't commit till the end, and if an exception kills your
> script, your transaction will be rolled back. I have a system for
> patching our database based on a script (written in Pike, not Python,
> but the same applies); if I have any sort of critical failure in the
> patch script, it'll bomb out as soon as I test it - but since I use
> PostgreSQL, all that DDL (eg "ALTER TABLE") is covered by
> transactional integrity (which it isn't with MySQL - another reason to
> be wary of MySQL), so my patch will be backed out, and I can fix it
> and start over. I don't need to have a Look Before You Leap approach
> to database changes - I can simply do stuff, and if it crashes, all's
> well. (That same script also has a system for catching errors at a
> mid-level point that means that the process doesn't terminate when
> there's an error; it supports full code reload, so once I fix the
> patch, I send the process a SIGHUP and it fetches from disk again.)
> *That* is error handling the safe way.
>

Oh, I get it! Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: user interfaces python3.x

2013-09-02 Thread Joe Junior
On 2 September 2013 14:00, Paul Rice  wrote:
>
> I know that most of my time will be writing . I dont think i specified very 
> well what im asking.
> What i mean by proper interface is a interface like for an app or something, 
> let me give u an example;
> Say i have made a phonebook just for this example and i want to use it like a 
> normal phonebook in your phone instead of in writing. So basically making it 
> like an app or something ?
> Does that make sense ? Lol

He's just messing with you. What you want is to write GUI (Graphical
User Interface) Application. The examples Steven cited like GTK and Qt
are libraries that provides it. The word "Interface" means a lot of
things in programming.




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


Re: user interfaces python3.x

2013-09-02 Thread Joe Junior
On 2 September 2013 14:30, Joel Goldstick  wrote:
> On Mon, Sep 2, 2013 at 1:16 PM, Joe Junior  wrote:
>> On 2 September 2013 14:00, Paul Rice  wrote:
>>>
>>> I know that most of my time will be writing . I dont think i specified very 
>>> well what im asking.
>>> What i mean by proper interface is a interface like for an app or 
>>> something, let me give u an example;
>>> Say i have made a phonebook just for this example and i want to use it like 
>>> a normal phonebook in your phone instead of in writing. So basically making 
>>> it like an app or something ?
>>> Does that make sense ? Lol
>>
>> He's just messing with you. What you want is to write GUI (Graphical
>> User Interface) Application. The examples Steven cited like GTK and Qt
>> are libraries that provides it. The word "Interface" means a lot of
>> things in programming.
>
> Except that those libraries don't work in Android phone environments.
> I've never looked into writing code for a phone, but I would suppose
> that a prerequisite for writing smart phone apps is to understand more
> in general how to write a software application.  Guessing from the way
> the OP poses his question, he has a lot more to learn than a specific
> GUI library.
>
> So, maybe the answers were a little facetious, but the question could
> be taken as either completely naive, or as completely pompous.  To
> answer the second interpretation is maybe more fun!

I'm always for some fun, I just  thought I should tell the OP what was
going on. :-) And Qt can work on Android, with some effort.

But you're absolutely right, mobile development can be quite harder
than desktop, and the OP has some studying to do. I'd recommend he
first tried some desktop development, a little googling on tkinter or
PyQt can do him good, since he wants to learn about GUI development,
even though it might not directly translate to mobile developtment.

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


Re: better and user friendly IDE recommended?

2013-09-12 Thread Joe Junior
On 12 September 2013 13:00, Veritatem Ignotam
 wrote:
> Is this thread going to evolve into your classic vim vs. emacs, sweet!

Who doesn't love those? ;-)

On 09/12/2013 11:47 AM, Paul Rudin wrote:
>
> Joshua Landau  writes:
>
>> If the time learning a set of tools is enough to make the choice
>> between tools, I suggest avoiding, say, Vim.
>
> That's a big if.
>
> If you expect to spend a lot of time editing text, code, etc. over the
> next few years then it's definitely learning at least one of vim or
> emacs to a reasonable degree of competency.

I kinda disagree. Though I use and love emacs as my main editor,
simple things you take for granted in modern editors are simply not
there, and you end up spending some precious time finding out how to
have it (like a right-margin marker). Of course that's not a real
issue, since in the end you'll have everything and much more after
configuring and saving your .emacs in the cloud so everything is
always to your liking.

But then comes another problem: we don't live in a bubble. If you'll
ever have to use another programmer's box, you're screwed (That's why
I avoid getting used to non-standard packages).

Not to mention the mental switch. Not everything I need to use has
emacs-binding (I guess the same is true for vim-binding) and, most of
the time, the binding sucks anyway.

But the point I really disagree is that typing/editing speed impacts
so much programmer's productivity. In my experience I spend a lot more
time as a programmer (big emphasis on "lot") reading, thinking and
designing then writing code. So I find a good navigation tool more
important.

My solution/suggestion for python: emacs (in cua-mode for me) with Jedi.

Joe
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-13 Thread Joe Junior
On 13 September 2013 15:39, John Gordon  wrote:
> In <76784bad-cd6d-48f9-b358-54afb2784...@googlegroups.com> 
> eamonn...@gmail.com writes:
>
>> they're making programming easier... by not coding as much. Oh well,
>> guess coding is dead :(
>
> Pressing keys on a keyboard was never the hard part of coding.
>

Nor the fun part.

Joe
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python GUI?

2013-09-13 Thread Joe Junior
On 13 September 2013 16:37,   wrote:
> I disagree with you. It's not hard, and I apologise if its ever sounded that 
> way, but it is the fun part for me. I love spending hours(days even) 
> debugging.
>
> Well, thanks all for depressing me. Time to give up programming and find 
> something else to do with my life.
> --
> https://mail.python.org/mailman/listinfo/python-list

lol! You made my day. :-D

Well, you can always ignore any and all graphical design tools if
you're working alone. And write all those Xs and Ys and widths and
heights all day long. None of the mentioned graphical toolkits forces
you to use them.

And if you like debugging, GUI is not the main dish! Try networking
and concurrent programming, loads and loads of fun!

Of course, that's lots of other unnecessary time consuming stuff you
can do. You just have to use your imagination.

Joe
-- 
https://mail.python.org/mailman/listinfo/python-list


Python boilerplate

2016-03-19 Thread Fernando Felix do Nascimento Junior
A simple boilerplate for those who don't know the structure of a project. 
https://goo.gl/lJRvS6

## Features

* Build and distribute with setuptools
* Check code style with flake8
* Make and run tests with pytest
* Run tests on every Python version with tox
* Code coverage with coverage.py

## Structure

Structure of the project in tree format.

├── CONTRIBUTING.md
├── LICENSE
├── Makefile
├── MANIFEST.in
├── module_name.py
├── README.md
├── requirements
│   ├── dev.txt
│   └── prod.txt
├── requirements.txt
├── setup.cfg
├── setup.py
├── tests.py
└── tox.ini

Fernando Felix
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python boilerplate

2016-03-20 Thread Fernando Felix do Nascimento Junior
@all

I released version 1.0.0 with a tiny glossary and explanation of each file in 
the boilerplate.

@Chris

I made the boilerplate with intent that everyone can understand, download and 
use quickly. So, I didn't put extra dependence like cookiecutter (that depends 
jinja, that depends markupsafe) to **just** replace fields and then run the 
project.

I also preferred to use .md instead .rst because it's more clean in my opinion 
and used by default in platforms like GitHub and Stackoverflow. See mkdocs to 
generate documentation with markdown.

In same way, I choose pytest because the default test framework is verbose and 
its CamelCase sux.

About entry_points maybe I'll consider it too, but I didn't understand why 
packages are best than modules... both can be reusable and not every project 
needs packages.

I looked your release shell script. It's very nice. In Flask GitHub repository 
has a pretty nice too. See it ~scripts/make-release.py.


Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list