Re: [Tutor] Value of tracebacks to malicious attackers?

2016-01-25 Thread Steven D'Aprano
On Sat, Jan 23, 2016 at 10:52:27PM -0600, boB Stepp wrote:
> From page 202 of "Python Crash Course":  "..., but it's also not a
> good idea to let users see tracebacks.
[...]
> How much concern do you give this in designing and implementing your
> production code?  

Me personally? Absolutely none at all, as my audience is (1) mostly me; 
(2) or other Python developers; (3) assumed to be reasonably technical; 
and (4) running the code on their own machine. There's nothing they can 
learn from the traceback that they don't already have access to.

But on occasions where I am writing for non-technical uses (i.e. an 
application rather than a library) I would handle it something like 
this in the main application:


if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
log.log("keyboard interrupt")
sys.exit()
except SystemExit as e:
log.log(e)
raise
else Exception as e:
log.log(e)
# show a GUI alert, or at least print a message
# to the screen
display_unexpected_error(e)
sys.exit(1)


or something like that. The point is to catch any unhandled exception, 
log it, possibly notify the user that something bad happened, and then 
exit. The traceback never gets shown.


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


Re: [Tutor] Why do I not get an error when I mistakenly type "humdrum.sigh_strenght" instead of the correct "humdrum.sigh_strength"?

2016-01-25 Thread Steven D'Aprano
On Sat, Jan 23, 2016 at 04:25:01PM -0600, boB Stepp wrote:

> I think I now have this nuked out.  I am only just now realizing how
> powerful .__dict__ is:
[...]
> self.__dict__[attribute_name] = attribute_value

Indeed, but generally speaking you hardly ever need to manually operate 
with a __dunder__ method or attribute. They're not quite private, but 
they are reserved, and normally you would use the public interface.

Instead of obj.__dict__[name], one should use one of the attribute 
functions:

getattr(obj, name)
setattr(obj, name, 999)
delattr(obj, name)

Instead of obj.__dict__, one should use vars(obj).

And of course, we never write obj.__len__() when we can write len(obj) 
instead. And so forth.



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


Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-25 Thread Oscar Benjamin
On 24 January 2016 at 19:47, Albert-Jan Roskam  wrote:
>>
>> You appear to be confusing ordered and sorted.

>   You are correct. Is there a difference in the way those terms are used 
> colloquially vs. in the field of Computer Science (Note: English is not my 
> mother tongue)? Anyway, this page seems to suggest that "Ordered" means "gets 
> messed up upon insertion, deletion, update: 
> http://stackoverflow.com/questions/1084146/what-is-the-difference-between-an-ordered-and-a-sorted-collection

An ordered collection will preserve its order if not mutated. If
mutated the operation will have a well defined effect on the order.
For example list.append(a) adds a new element and the new element will
always be at the end of the list regardless of its value. A list might
be in sorted order (i.e. after you have called the .sort() method) but
when you call append the new element will go at the end so that it is
no longer sorted.

A sorted collection has a sort key and ensures that it always has an
order that corresponds to sorting by that key. So when you add a new
element the container will somehow ensure that it ends up in the right
position to keep the container sorted.

If you use an ordered container initialised with sorted data (as you
seem to be doing) then the distinction is only important if you mutate
the container. Specifically in the case of an OrderedDict which you
want sorted by keys the distinction is only important if you add new
keys to the OrderedDict. Any new keys will be implicitly added at the
end of the OrderedDict's ordering (as if you called append on a list).
Removing a key with e.g. pop() is fine and changing the value
associate with a key is fine: only adding new keys will break the sort
order.

So if you're not adding new keys to the OrderedDict as you work then
there is no reason not to use it in this situation.

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


Re: [Tutor] Why is an OrderedDict not sliceable?

2016-01-25 Thread Oscar Benjamin
On 24 January 2016 at 20:29, Albert-Jan Roskam  wrote:
>> I guess that the authors of OrderedDict just didn't really consider
>> this to be very useful. Apart from having ordered iteration
>> OrderedDict is not really that deeply thought out. There's a thread on
>> python-ideas about the inconsistent behaviour of the keys and values
>> views and equality comparison of OrderedDicts on python-ideas at the
>> moment:
>>
>> https://mail.python.org/pipermail/python-ideas/2015-December/037472.html
>
> As I said in a prior email: That is SCARY! Should I just avoid OrderedDict
> like the plague?

No, OrderedDict works fine. Just in answer to your question about why
this particular feature isn't there:

1) The slicing thing is conceptually not that well defined. To me it
was obvious what you meant but I suspect that many people would find
it confusing or unexpected. (see e.g. the initial responses from Steve
and Ben in this thread)
2) The OrderedDict isn't really that deeply thought out beyond "I want
a dict that has a consistent iteration order".

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


Re: [Tutor] Change datatype for specific columns in an 2D array & computing the mean

2016-01-25 Thread Oscar Benjamin
On 24 January 2016 at 17:24, Peter Otten <__pete...@web.de> wrote:
>
> I'm an amateur with numpy, and unfortunately my favourite search engine
> didn't come up with a numpy-specific way to group rows in a 2D array.

What do you mean by "group rows"?

I thought the OP's problem is really to filter rows which I already
showed how to do in numpy.

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


Re: [Tutor] Change datatype for specific columns in an 2D array & computing the mean

2016-01-25 Thread Peter Otten
Oscar Benjamin wrote:

> On 24 January 2016 at 17:24, Peter Otten <__pete...@web.de> wrote:
>>
>> I'm an amateur with numpy, and unfortunately my favourite search engine
>> didn't come up with a numpy-specific way to group rows in a 2D array.
> 
> What do you mean by "group rows"?

Given a table you can specify columns as keys and in the simplest case one 
column where you apply an aggregate function over the sets of rows with the 
same key.

If I understand you correctly you are doing that for a single known key, 
whereas I considered finding the keys part of the task. In SQL you'd spell 
that

[prob 1]
select key1, key2, sum(value) from some_table group by key1, key2;
 
> I thought the OP's problem is really to filter rows which I already
> showed how to do in numpy.

You solve

[prob 2] 
select sum(value) from some_table where key1=? and key2=?;

You'll eventually get from [prob 2] to [prob 1], but you need a few lines of 
Python.

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


Re: [Tutor] Change datatype for specific columns in an 2D array & computing the mean

2016-01-25 Thread Oscar Benjamin
On 25 January 2016 at 13:14, Peter Otten <__pete...@web.de> wrote:
>> What do you mean by "group rows"?
>
> Given a table you can specify columns as keys and in the simplest case one
> column where you apply an aggregate function over the sets of rows with the
> same key.
>
> If I understand you correctly you are doing that for a single known key,
> whereas I considered finding the keys part of the task. In SQL you'd spell
> that
>
> [prob 1]
> select key1, key2, sum(value) from some_table group by key1, key2;
>
>> I thought the OP's problem is really to filter rows which I already
>> showed how to do in numpy.
>
> You solve
>
> [prob 2]
> select sum(value) from some_table where key1=? and key2=?;
>
> You'll eventually get from [prob 2] to [prob 1], but you need a few lines of
> Python.

Oh okay. It wasn't clear to me that was what the OP wanted.

You can do it in numpy by combining a few pieces. First we define an array:

In [1]: import numpy as np

In [2]: a = np.array([[5, 1.0], [1, 3.0], [5, 2.0], [1, 4.0], [5, -1.0]])

In [3]: a
Out[3]:
array([[ 5.,  1.],
   [ 1.,  3.],
   [ 5.,  2.],
   [ 1.,  4.],
   [ 5., -1.]])

Now we need to sort the array:

In [4]: a = np.sort(a, axis=0)

In [5]: a
Out[5]:
array([[ 1., -1.],
   [ 1.,  1.],
   [ 5.,  2.],
   [ 5.,  3.],
   [ 5.,  4.]])

Now we can access the 2nd column easy:

In [6]: a[:, 1]
Out[6]: array([-1.,  1.,  2.,  3.,  4.])

But we want to split that column according to the first column. We can
use the split function if we know the indices and we can get them with
diff:

In [7]: np.diff(a[:, 0])
Out[7]: array([ 0.,  4.,  0.,  0.])

n [14]: np.nonzero(np.diff(a[:, 0]))[0]
Out[14]: array([1])

In [15]: indices = np.nonzero(np.diff(a[:, 0]))[0] + 1

In [16]: indices
Out[16]: array([2])

Now we can use these to split the second column of the sorted array:

In [17]: grouped = np.split(a[:, 1], indices)

In [18]: grouped
Out[18]: [array([-1.,  1.]), array([ 2.,  3.,  4.])]

In [19]: list(map(np.mean, grouped))
Out[19]: [0.0, 3.0]

It's not exactly straight-forward but numpy has all the primitives to
make this reasonably efficient. If we also want the list of keys then:

In [23]: a[np.concatenate([[0], indices]), 0]
Out[23]: array([ 1.,  5.])

Altogether:

import numpy as np

a = np.array([[5, 1.0], [1, 3.0], [5, 2.0], [1, 4.0], [5, -1.0]])

a = np.sort(a, axis = 0)
indices = np.nonzero(np.diff(a[:, 0]))[0] + 1
means = list(map(np.mean, np.split(a[:, 1], indices)))
keys = a[np.concatenate([[0], indices]), 0]
group_means = dict(zip(keys, means))

print(group_means) # {1.0: 0.0, 5.0: 3.0}


If you want to key on multiple columns use lexsort instead of sort and
sum the diff array along rows but otherwise it's the same principle.

Looks easier with pandas :)

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


[Tutor] What's pure OO? [was Re: Why do I not get an error when I mistakenly type ...]

2016-01-25 Thread Steven D'Aprano
On Sat, Jan 23, 2016 at 08:30:48PM +1100, Cameron Simpson wrote:

> That is the pure OO way; 

Is this the room for an argument? I'd like the full half hour please.

http://www.montypython.net/scripts/argument.php


Without wishing to single out Cameron specifically, I'd like to take 
exception to the way folks are tossing around the term "pure OO". I 
don't think that's a term that adds much light to the discussion, and I 
think it risks being understood as "real OO", a term which is downright 
harmful.

At the very least, people ought to define their terms. What on earth is 
"pure OO"?

If I were to guess, I would think of pure OO in one of two ways:

(1) All values in the language are objects.

That describes Python: everything in Python, modules, ints, strings, 
functions, even classes themselves, are objects. That makes Python as 
"pure" an object-oriented language as it is possible to get.

In comparison, Java fails miserably: unlike Python, but default Java 
treats numbers, strings, booleans as native "unboxed" values, not 
objects.

This is the definition of "pure OO" language given by Wikipedia:

https://en.wikipedia.org/wiki/Object-oriented_programming#OOP_languages


(2) Alternatively, "pure OO" might mean a language which uses only OO 
syntax: alist.len() not len(alist).

Obviously Python is not pure in that sense, but then (i) I don't know 
any language which is, most languages allow non-OO syntax at least for 
arithmetic; and (ii) syntax is the most superficial and unimportant part 
of Object Oriented Programming. 


(3) Others (but not I) might fall for the "No True Scotsman" fallacy and 
use "pure OO" to mean "proper OO", for whatever definition of "proper" 
they like. Unfortunately, or perhaps fortunately, OO covers a lot of 
ground, and very little is mandatory. Just as true Scotsmen do sometimes 
wear trousers, and eat porridge with honey and milk, so almost any 
feature of OOP is optional:

(a) Classes are optional; prototype-based languages like Javascript 
and Lua are no less OO than class-based languages.

(b) Subtyping and inheritence are optional. Some people like to 
reserve the term "object-based" for languages with objects but no 
inheritence. Others distinguish between languages with nominal 
subtyping, like C++ and Swift, and structural subtyping, like Ocaml and 
Go. (Python arguably has both, as duck-typing is a form of 
structural subtyping.)

I could go on, but suffice to say that I will strongly object (pun 
intended) to any suggestion that Python is not a "proper" or even "pure" 
OO language because it lacks certain features some other OOP languages 
provide.

For example, it's popular in certain circles to say that No True OO 
Language lacks information-hiding (sometimes wrongly called 
encapsulation). Since Python has no "private" keyword, Python cannot be 
a proper OOP language like Java, or so they say.

But Java's private variables are not that private:

http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html

and Python's cooperative information hiding ("just ignore anything 
starting with a single underscore, since that's private") is actually no 
less private than Java's.




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


[Tutor] Need Help

2016-01-25 Thread Parinay Mahakur
Hello Tutors,


I need a program that should enable me to read values from a large number
of ASCII files and then I have to plot desired values - In this file
headings for all columns are also given. The link for the file is -

http://jsoc.stanford.edu/SUM75/D780005879/S0/hmi.rdVfitsf_fd15.2171.015.355.0.-67.5.-20.0.fit.out
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Help!

2016-01-25 Thread Chelsea G
Hi,
I am trying to create a keyword search, so that someone can type in  a key
phrase and then the output be the value with the key. I have some code
already done but having some trouble getting it to work.
import csv
import json
import sys
from collections import defaultdict
from collections import Counter


class dictionary():
def __init__(self):
self.dict = defaultdict(list)
self.counted_dict = defaultdict(list)
self.grouped_dict = defaultdict(list)
self.other_dict = defaultdict(list)
self.final_dict = defaultdict(list)
self.total_dict = defaultdict(list)
self.keyword_dict = defaultdict(list)
def populate_dict(self, filename):
with open (filename, 'rb') as f:
reader = csv.reader(f)
next(reader, None)
for row in reader:
self.dict[row[2]].append(row[3])
def total_counts(self):
for key in self.dict.keys():
total = 0
b = Counter(self.dict[key])
for value in b:
total += b[value]
self.total_dict.update({key: str(total)})
def all_counts(self):
data_count = Counter()
for key in self.dict.keys():
self.counted_dict.update({key: Counter(self.dict[key])})
def grouped_counts(self):
for key in self.dict.keys():
total = 0
c = Counter(self.dict[key])
for value in c:
if c[value] >= 5:
self.grouped_dict.update({value: key + ': ' + str(c[value])})
elif c[value] <= 4:
total += c[value]
self.other_dict.update({key: 'other: ' + str(total)})
self.final_dict = self.grouped_dict, self.other_dict, self.total_dict

def keyword_items(defaultdict, lookup):
defaultdict = {' Tool Issue': ['Project Tool'], 'All catalogs missing or
not updating': ['Design Tool']}
for value, key in defaultdict.items():
for v in value:
if lookup in v:
return key
def json_output(self):
with open ('testing.txt', 'w') as text_file:
json.dump(self.final_dict, text_file, sort_keys = True, indent = 4)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Noob: nested if-clauses

2016-01-25 Thread STF
Thanks to Joel and Alan for replying.

On 24 January 2016 at 22:08, Alan Gauld  wrote:

> On 24/01/16 19:42, STF wrote:
>
> > Let's see the following instructions:
> > 
> > if condition_A:
> > instruction_1
> > instruction_2
> > if condition_B:
> >   instruction_3
> >   instruction_4
> > instruction_5
> > else:
> > instruction_6
> > 
> >
> > * How to make Pythom understand that instruction_4 is a part of
> condition_B
> > if-clause but not a direct instruction of condition_A if-clause?
>
> You've done it above by the indentation.
>

It's a total fluke.  I put the indentation like this to *visually* help
myself understand what I was going to write.

In the Python tutorial that I was using, the author only told us to use
indentation, without emphasizing on the size of it.


> > to make Python understand that instruction_5 is outside of condition_B
> > if-clause?  Just by the number of white spaces in front of every
> > instruction??
>
> Yes, the indent level tells Python where the instruction should be.
>
> > * How to make Python understand that "else" belongs to the first
> > condition_A if-clause, not to the immediate condition_B if-clause?
>
> Again you've done it already, just use the indent level.
>
> > * Suppose I put four white spaces in front of instruction_1, and then
> "tab
> > key" in front of instruction_2, would this break things?
>
> In Python 2 things are a wee bit flexible but in Python 3 less so.
> But in general avoid mixing them, stick to spaces. Most Python
> programmers set their text editor/IDE to convert tabs to
> spaces(usually 4)
>
> > most intelligent text editors would insert automatically a tab in place
> of
> > 4 white spaces after we press Enter on a line with 4 leading white
> spaces.
>
> Most can also be configured not to use tabs at all and
> for Python that's better. Tell us your editor and somebody
> can probably advise on optimum settings.
>

As I'm a newbie, I'm mostly using Python IDLE but sometimes I would use
Programmer's Notepad.


>
> > * Do I really need to keep the consistency of 4 white spaces?  Not one
> more
> > or one less?
>
> No you can have as many or as few as you like in your own code,
> just be consistent. 4 just happens to be esy to read. And its
> the standard for library code so if you want to write some code
> for the standard library you will need to use 4 spaces. In
> the interpreter (>>>) I often only use 2 just to save typing.
> But for production code I stick with 4 - not a problem since
> the editor(vim) does most of the work for me.
>

Let me ask an alternative question.  Suppose I have something like this:


if condition_C:
instruction_10
   instruction_11
 instruction_12

There are 4 spaces in front of instruction_10, 3 spaces in front of
instruction_11 and 5 spaces in front of instruction_12.

What would happen to instruction_11 and instruction_12?  Would Python
ignore them?  Or would they be considered instructions outside the
if-clause?

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


[Tutor] Variation in game of life in python solution by numpy method

2016-01-25 Thread Mahesh Dabhade
Hi...I have problem in game of life...
But I have 4 states rather than just two states like live and dead...
These are
0 : bare earth
1: grass 2: prey 3: predator
And rules are
1 )if 2 surrounded by less than 2 of 1 then 2 becomes 1.starvation
2)if 0 surrounded by more than 0 of 1 then 0 becomes 1
3)if 1 surrounded by more than 1 of 2 then 1 will be 0
4)if 3 surrounded by less than 2 of 1 then  3 becomes 0
Now I am not even able to count the neighbors
Can u plzz help me out in counting neighbours...
N even better can u plzz send the program code
It will be great help
Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's pure OO? [was Re: Why do I not get an error when I mistakenly type ...]

2016-01-25 Thread Alan Gauld
On 25/01/16 15:02, Steven D'Aprano wrote:
> On Sat, Jan 23, 2016 at 08:30:48PM +1100, Cameron Simpson wrote:
> 
>> That is the pure OO way; 
> 
> Is this the room for an argument? I'd like the full half hour please.

Personally I see OOP as a style thing rather than a language
issue. And I do think there is some sort of a "pure" definition
in all the object model theory papers that abound on the subject
in CS departments around the planet. (But that still leaves a
lot of wriggle room due to differences in opinion among the gurus)

But like most "pure" approaches it's thoroughly impractical in
isolation. As a result no pure OOP language exists because
it would be unusable. (Just like with pure FP, another case
where cries of purity are rife.)

OTOH striving towards purity is no bad thing. There is usually
a good reason lurking in the background. Otherwise we'd all
still be programming with goto and globals and variable names
like A$... But structured programming too has its
purists... remember single exit points anyone? (Actually F#
does insist on those!)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Need Help

2016-01-25 Thread Alan Gauld
On 25/01/16 16:09, Parinay Mahakur wrote:

> I need a program that should enable me to read values from a large number
> of ASCII files and then I have to plot desired values

Have you considered a spreadsheet like Excel?
You could write a couple of macros to read the files
and to generate the plots.

If you want to do it in Python then we need a lot more
details, and some visibility of the code you've written
so far.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Help!

2016-01-25 Thread Alan Gauld
On 25/01/16 17:39, Chelsea G wrote:
> Hi,
> I am trying to create a keyword search, so that someone can type in  a key
> phrase and then the output be the value with the key. 

I'm not completely clear what you mean by a key phrase?
Do you mean a phrase matching the keys in your dictionary?(In which case
its easy) or domyou mean a random phrase? In which case what should happen?

> I have some code
> already done but having some trouble getting it to work.

Sadly you haven't posted in plain text so its lost all indentation,
making it nearly unreadable. Can you repost in plain text please?

> class dictionary():
> def __init__(self):
> self.dict = defaultdict(list)
> self.counted_dict = defaultdict(list)
> self.grouped_dict = defaultdict(list)
> self.other_dict = defaultdict(list)
> self.final_dict = defaultdict(list)
> self.total_dict = defaultdict(list)
> self.keyword_dict = defaultdict(list)
> def populate_dict(self, filename):
> with open (filename, 'rb') as f:
> reader = csv.reader(f)
> next(reader, None)
> for row in reader:
> self.dict[row[2]].append(row[3])
...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Noob: nested if-clauses

2016-01-25 Thread Danny Yoo
> if condition_C:
> instruction_10
>instruction_11
>  instruction_12
> 
> There are 4 spaces in front of instruction_10, 3 spaces in front of
> instruction_11 and 5 spaces in front of instruction_12.
>
> What would happen to instruction_11 and instruction_12?  Would Python
> ignore them?  Or would they be considered instructions outside the
> if-clause?
>

You should get an error at program parse time, as the system keeps track of
the indentation used to begin new blocks.  If it sees an indent level that
is inconsistent with those beginnings, it should know to signal a parse
error.

Please feel free to ask questions.  Good luck!

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


Re: [Tutor] Need Help

2016-01-25 Thread Mark Lawrence

On 25/01/2016 16:09, Parinay Mahakur wrote:

Hello Tutors,

I need a program that should enable me to read values from a large number
of ASCII files and then I have to plot desired values - In this file
headings for all columns are also given. The link for the file is -

http://jsoc.stanford.edu/SUM75/D780005879/S0/hmi.rdVfitsf_fd15.2171.015.355.0.-67.5.-20.0.fit.out


Start here https://docs.python.org/3/tutorial/index.html as we don't 
write code for you.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: [Tutor] Variation in game of life in python solution by numpy method

2016-01-25 Thread Mark Lawrence

On 25/01/2016 17:53, Mahesh Dabhade wrote:

Hi...I have problem in game of life...
But I have 4 states rather than just two states like live and dead...
These are
0 : bare earth
1: grass 2: prey 3: predator
And rules are
1 )if 2 surrounded by less than 2 of 1 then 2 becomes 1.starvation
2)if 0 surrounded by more than 0 of 1 then 0 becomes 1
3)if 1 surrounded by more than 1 of 2 then 1 will be 0
4)if 3 surrounded by less than 2 of 1 then  3 becomes 0
Now I am not even able to count the neighbors
Can u plzz help me out in counting neighbours...
N even better can u plzz send the program code


Please show us the code that you have so far as we do not write code for 
you.



It will be great help
Thanks


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: [Tutor] Noob: nested if-clauses

2016-01-25 Thread Alan Gauld
On 25/01/16 15:52, STF wrote:

> It's a total fluke.  I put the indentation like this to *visually* help
> myself understand what I was going to write.

That's one of the good things about Python, if it looks right
it very often is right.

> In the Python tutorial that I was using, the author only told us to use
> indentation, without emphasizing on the size of it.

Quite right the amount is not important(syntactically at least) provided
you are consistent.

> As I'm a newbie, I'm mostly using Python IDLE but sometimes I would use
> Programmer's Notepad.

I don't know PN but IDLE will keep you right most of the time.

> Let me ask an alternative question.  Suppose I have something like this:
> 
> 
> if condition_C:
> instruction_10
>instruction_11
>  instruction_12
> 
> There are 4 spaces in front of instruction_10, 3 spaces in front of
> instruction_11 and 5 spaces in front of instruction_12.
> 
> What would happen to instruction_11 and instruction_12?  

One of the best things about Python is the interpreter.
Just try it and see. It's much faster than posting a question
here and you can be sure it's the correct answer! If you
don't understand what you see, then come here.

Just use some print statements or simple assignments
for example:

>>> if True:
...print 'in the if'
...   print 'still here'
...  y = 5 * 6
...

what happens?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Variation in game of life in python solution by numpy method

2016-01-25 Thread Alan Gauld
On 25/01/16 17:53, Mahesh Dabhade wrote:

> Now I am not even able to count the neighbors

Then start with that as a first step.

> Can u plzz help me out in counting neighbours...

We need to see what you are doing to be able to help

> N even better can u plzz send the program code

No, we won't do your work for you, we only
try to help you do it.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Can This Script Be Modified to Read Many Files?..

2016-01-25 Thread Sam Starfas via Tutor
Hi,I am very new to Python, but having fun learning. 
I need to have a script read all of the XML files contents that are in a 
directory, pull out the contents of an element, in my case , and 
list them in an output file. I have this script that does exactly what I need. 
But in my beginning Python class we didn't go over reading all files, only one 
file at a time. 
Can the below script be modified to scan/read all of the XML files in a 
directory instead of just the file typed into the script? If so, how do I do 
this?
Thanks for all the help.Sam

import xml.etree.ElementTree as ETtree = ET.parse('TEST.xml')   <-- Want to 
read all the files in directory, not type in the filename.root = tree.getroot()

for uicontrol in root.iter('uicontrol'):    print(uicontrol.text)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can This Script Be Modified to Read Many Files?..

2016-01-25 Thread Alan Gauld
On 25/01/16 21:34, Sam Starfas via Tutor wrote:

> Can the below script be modified to scan/read all of the XML files in a 
> directory

You could do it manually using

for file in glob.glob("*.xml"):

But you need to think about all the other possible file
endings too.

Or you could look at the fileinput module which takes a
different approach.

Finally if you need to process subdirectories too you
can use the os.walk() function

The Python docs describe how to use glob, fileinput
and os.walk.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Can This Script Be Modified to Read Many Files?..

2016-01-25 Thread Bob Gailer
On Jan 25, 2016 6:26 PM, "Sam Starfas via Tutor"  wrote:
>
> Hi,I am very new to Python, but having fun learning.
> I need to have a script read all of the XML files contents that are in a
directory, pull out the contents of an element, in my case , and
list them in an output file. I have this script that does exactly what I
need. But in my beginning Python class we didn't go over reading all files,
only one file at a time.
> Can the below script be modified to scan/read all of the XML files in a
directory instead of just the file typed into the script? If so, how do I
do this?
> Thanks for all the help.Sam
>
> import xml.etree.ElementTree as ETtree = ET.parse('TEST.xml')   <-- Want
to read all the files in directory, not type in the filename.root =
tree.getroot()
>
> for uicontrol in root.iter('uicontrol'):print(uicontrol.text)
As you probably noticed your code got mangled this is probably due to the
email program you're using what you should do is have it send plain text so
the formatting will be preserved.
I hope it's obvious that you will need a loop to process multiple files so
I'm going to assume that what you want is how to get a list of files
meeting some criteria in a directory. I'm dictating into my cell phone
right now so I can't look some things up but my presumption is you will
need to use the glob function in the glob module to get the list of
filenames, then iterate over that list. Hope that helps.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor