Re: [Tutor] Help Please

2019-02-21 Thread DL Neil

Mario,

On 21/02/19 3:30 AM, Mario Ontiveros wrote:

Hello,
 I am new to python and have been stuck on this for a while. What I am 
trying to do is to remove rows with void, disconnected, and error on lines. The 
code I have does that, the only problem is that it removes my header because 
void is in header. I need to keep header.
with open("PSS.csv","r+") as f:
 new_f = f.readlines()
 f.seek(0)
 for line in new_f:
 if "Void" not in line:
 if "Disconnected" not in line:
 if "Error" not in line:
  f.write(line)
 f.truncate()



Would it be 'safer' to create a separate output file?

Rather than reading the entire file (easily managed if short, but 
unwieldy and RAM-hungry if thousands of records!), consider that a file 
object is an iterable and process it one line/record at a time.


with open( ... ) as f:
header = f.readline()
# deal with the header record
for record in f:
function_keep_or_discard( record )
#etc


In case it helps you to follow the above, and possibly to learn other 
applications of this thinking, herewith:-


An iterable matches a for-each-loop very neatly (by design). It consists 
of two aspects: next() ie give me the next value (thus for each value in 
turn), and the StopIteration exception (when next() asks for another 
value after they have all been processed). The for 'swallows' the 
exception because it is expected. Hence, you don't need to try...except!


Something a lot of pythonistas don't stop to consider, is that once code 
starts iterating an object, the iteration does not 'reset' until 
"exhausted" (unlike your use of f.seek(0) against the output file). 
Accordingly, we can use a 'bare' next() to pick-out the first (header) 
record and then pass the rest of the job (all the other next()s) to a 
for-each-loop:


with open( ... ) as f:
header = next( f )  # grab the first record
# deal with the header record
for record in f:# iterate through the remaining records
#etc

--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] LPTHW ex15 question

2019-03-21 Thread DL Neil

Kayla,

On 22/03/19 1:43 AM, Jones, Kayla wrote:

I am working through excersise 15 of LPTHW and am getting an error message in 
powershell that I can't figure out. I've attached a screenshot to help.  Any 
suggestions would be appreciated.



Attachments don't seem to work on the mailing list.

Plus, if you copy-paste code (and errmsgs) then we can do the same!
(to reproduce the problem/save time coding a fix)


--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cant get it to run right

2019-03-28 Thread DL Neil

On 29/03/19 12:55 PM, Sveum, Christian wrote:

I am new and I have tried everything I can think I of. I want it to run like a 
converstion.
print(" I am Bob")

...

What is not working?
How far does the program run before stopping?
What error message are you seeing?
(why won't you share it with us?)

--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for some direction

2019-05-11 Thread DL Neil

Cranky,

It is a little difficult to answer your question.

First impression is that your experience gives you good ideas of how to 
solve the problem. Some of them may not suit the Python environment as 
well as (say) that of PHP/MSFT. So, a learning opportunity there too.


Second impression is that there are a lot of moving parts. How many of 
them do you know well, and how many are learning-targets? Trying to 
tackle 'too much' that is 'new' may result in heavy frustration. (no 
mention of skill-levels, so 'just sayin')


The web-ref is not a book, but a *simple* article. It will serve, as 
long as you stick within the narrow scope of that article. The instant 
you deviate or customise, you're 'on your own'. For this reason, my 
recommendation is always a (proper/full) book*, if at all possible. You 
speak of MVC, so one (of many) Python web framework is Mig Grinberg's 
"Flask". Apart from his own, there are several other books which cover 
this subject. Following such a text will enable you to start-out on 'toy 
examples' and then gather expertise. Likely, you will re-shape this 
project whilst learning.


* I used the term "book" but the last person to whom I recommended such 
couldn't afford the cost, and these days there are many excellent 
on-line and equally structured alternatives, eg Python courses on 
Coursera.org and edX.org (both 'freemium' offerings) - IIRC(?) Flask is 
available on Lynda (LinkedIN).



That said, let's try responding to each of your points:-


On 12/05/19 6:59 AM, Cranky Frankie wrote:

I'm a long time IT professional trying to teach myself object-oriented
programming. As such I want to build a traditional PC app using MVC (Model
- View - Controller) architecture. Just want to make sure I'm heading about
this in the best way so I'm looking for some direction.

For the Model or persistence layer I want to use SQLite. For the View or
GUI I want to use wxPython. For the Controller I want to of course use
Python. I'm also planning on using Git for source control.

1) For the IDE I'm most comfortable with Netbeans/Java, but I'm forcing
myself to try and get comfortable with PyCharm. Is it worth sticking it out
with PyCharm, or should I go with the Python module in Netbeans? Or is
there another IDE I should look at?


To my observation an IDE is less important in Python (than for highly 
structured, strongly typed, compiled, ... languages). My advice is, once 
you've chosen and found that it works, do NOT switch editor/IDE in 
anything less than one year. Under the 80-20 'rule', we use a basic few 
editing 'features' to do most of our work. Thus, it stands to reason 
that it will take periods of 'real time' before you decide 'there must 
be an easier way' to achieve some functionality and go looking in the 
editor's menus/help/etc to see if/what it might be! The other aspect is 
that 'religious wars' are fought over "which is the best editor/IDE" 
style questions. If you believe 'everyone' you'll 'jump' so often that 
you'll never figure-out 'which'. So, given that PyCharm is 
purpose-built, has a good reputation, and you have already used it: "if 
it ain't broke, why fix it"? (NB I don't use it, but have in the past)




2) For wxPython I'm finding a lot of the documentation is outdated. Is this
book any good:

http://www.blog.pythonlibrary.org/2019/05/08/creating-gui-applications-with-wxpython-now-available/

Or is there a better book/course/website I should be working with? Or is
there a better grahpics framework at this point for a traditional desktop
app?


- attempted to tackle in 'strategy' comments, above



3) For the O-O part, I'm comfortable with Inheritance and Composition. Do I
need to worry about any of the more advanced design patterns? This app will
be for vehicle ownership - tracking maintenance, etc. Nothing fancy.


At risk of creating a dichotomy, whilst there are books which attempt to 
'translate' the original gang-of-four patterns (and more) into 'Python', 
none has really impressed. "Pythonista" talk of "pythonic" solutions. 
Personal observations when learning Python (as if I'm not still...) 
included the need to desist from trying to solve a problem in 
xyz-other-language and 'translate' that to Python, but to learn how 
Python's construction enables its own solution-approach - sometimes 
quite distinctive. My favorite simple example of this is that many other 
languages offer do/for-loops. However Python's construct should be 
called for-each because it does not manage an index, eg loop-around 
doing something with array[index]; but instead/additionally "iterates" 
over a "collection", eg for item in list: ... Which also disposes of the 
need to learn the GoF iterator pattern as a "pattern" - but does not 
excuse you from understanding the "idiom". Once again, such are best 
(IMHO) learned from the cohesive and comprehensive coverage of a decent 
Python book*, cf numerous and unrelated web/blog/etc entries.




4) I plan to write my Use Case in Libre 

Re: [Tutor] Two Scripts, Same Commands, One Works, One Doesn't

2019-05-18 Thread DL Neil

Stephen,


On 16/05/19 12:16 AM, Stephen P. Molnar wrote:
I am writing scripts to semi-automate some of my Quantum Chemistry 
software and have encountered a problem that has me baffled. The two 
scripts have the same form, the only difference being the commands. One 
script works, the other bombs.



Blast from the past! I thought I'd finished with nerve agents, 
receptors, and ligands back in 1990-1. The memories have not improved 
with age!



Taking the first question, ie 'two scripts which appear identical but 
are not':-


Nothing 'popped' during a quick visual scan.

Linux (which it is assumed you are using) has two basic built-in 
commands/pgms: diff and cmp (difference and compare). For occasions when 
I want to compare directories first, and probably contained-files 
thereafter, I use "Meld".



As to the second: +1 to removing the extra moving-parts, like Spyder, 
and running directly from the cmdLN (simplify, simplify).



Even though accuracy and precision are important, this is the Tutor 
list, so don't worry too much about the terminology. Most of us, young 
or old will have recognised what you meant. Whilst I can't recall the 
last time I used the term "bomb", I'm guessing that "abend" wouldn't 
pass muster either...



--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for some direction

2019-05-18 Thread DL Neil

On 13/05/19 10:56 AM, boB Stepp wrote:

On Sun, May 12, 2019 at 5:19 PM boB Stepp  wrote:

On Sun, May 12, 2019 at 1:05 PM David L Neil
 wrote:

I'm using Gnome Terminal under Fedora (Linux). This allows multiple
terminals in tabs (and thus Ctrl-Tab rapid-switching). However, it
irritates me that whilst I can set "profiles" for particular purposes;
there does not seem to be a way to save a 'session'. Thus each time
Terminal re-starts, I have to re-build each terminal, manually.

(suggestions of other similar tools would be most welcome)


I may be mistaken, but I think that a terminal multiplexer like tmux
(https://github.com/tmux/tmux/wiki) is capable of session management.
I have no personal use of tmux, but have been intrigued enough about
others referring to it that eventually I will get around to seriously
checking it out.


Actually, tmux is starting to look more and more interesting.  David,
I think you might this helpful.  I am currently looking at an
introduction to tmux by a Stack Overflow developer.  This article is
at https://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/
(There was a link to this on the tmux wiki I sent out a link to
earlier.)  I think I may start playing around with this!


Thanks Bob. Am taking it for a spin...

--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiprocessing with many input input parameters

2019-07-11 Thread DL Neil

Sydney,

1 There have been many projects to look at cells, division, 
multiplication, ... It is worth researching the Python eco-system in the 
expectation of saving yourself time and effort!


2 The latest releases of Python (such as you quote) offer updated 
asyncio module(s) for multiprocessing, ie be careful if you are reading 
older articles! We haven't discussed hardware. Most modern PC CPUs offer 
multiple "cores". Assuming (say) four cores, asyncio is capable of 
running up to four processes concurrently - realising attendant 
acceleration of the entirety.

(admittedly, I tend to limit my ambitions to number_of_cores - 1)



On 12/07/19 3:40 AM, Mike Barnett wrote:

If you're passing parameters as a list, then you need a "," at the end of the 
items.  Otherwise if you have something like a string as the only item, the list will be 
the string.

list_with_one_item = ['item one',]


@mike

-Original Message-
From: Shall, Sydney 
Sent: Wednesday, July 10, 2019 11:44 AM
To: tutor@python.org
Subject: [Tutor] Multiprocessing with many input input parameters

I am using MAC OS X 10.14.5 on a MAC iBook I use Python 3.7.0 from Anaconda, 
with Spyder 3.3.3

I am a relative beginner.

My program models cell reproduction. I have written a program that models this 
and it works.

Now I want to model a tissue with several types of cells. I did this by simply 
rerunning the program with different inputs (cell characteristics). But now I 
want to send and receive signals between the cells in each population. This 
requires some sort of concurrent processing with halts at appropriate points to 
pass and receive signals.

I thought to use multiprocessing. I have read the documentation and reproduced 
the models in the docs. But I cannot figure out how to feed in the data for 
multiple parameters.

I have tried using Pool and it works fine, but I can only get it to accept 1 
input parameter, although multiple data inputs with one parameter works nicely.

So, my questions are;

   1.  Is multiprocessing the suitable choice.
   2.  if yes, how does one write a function with multiple input parameters.

Thank s in advance.

Sydney

Prodessor. Sydney Shall
Department of Haematological Medicine
King's College London
123 Coldharbour Lane
London SE5 9NU
ENGLAND
E-Mail: sydney.shall
(Correspondents outside the College should add @KCL.AC.UK)
TEL: +44 (0)208 48 59 01

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor