Re: [Tutor] Help Noob Question

2014-03-28 Thread spir

On 03/28/2014 02:17 AM, Alan Gauld wrote:

On 27/03/14 21:01, Chris “Kwpolska” Warrick wrote:

On Mar 27, 2014 8:58 PM, "Alan Gauld" mailto:alan.ga...@btinternet.com>> wrote:
 >
 > On 27/03/14 06:43, Leo Nardo wrote:
 >>
 >> Im on windows 8 and i need to open a file called string1.py that is on
 >> my desktop,
 >
 >
 > Thats your first problem. Its usually a bad idea to store your python
code on the desktop, because the desktop is a pain to find from a
command line.

Painful? How painful can `cd Desktop` be? Certainly less than `D:`
followed by `cd PythonProjects`…


Because the desktop is hardly ever anywhere near where the cmd prompt lands you.

So cd desktop usually results in an error and typing the full path (even with
directory completion, Mark) is a royal pain because
you have to remember where it is. There is no ~ shortcut in Windows.
On my system that means typing something like:

C:\Documents and Settings\alang\Desktop


Can't you make a symlink pointing to Desktop? (in C:\ or anywhere else)


or some such nonsense, complete with spaces in the path that add
to the pain.

Now I probably could use something like cd %HOMEPATH% to get to what Windows
laughingly considers my 'home' directory and then find it
from there but even so its not always obvious depending on the
windows version and the install options used. And of course if
the file happens to be on the "all users" Desktop looking in my
local Desktop doesn't help.

I find it much easier to know where my Python code lives from wherever I happen
to find myself in the labrynthian file system that is Windows.


Well, all filesystems are labyrinthians, AFAIK (at least, for people like me who 
cannot learn by heart). I never know where things are are, in my box (Linux), 
apart from my own home.


d

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


[Tutor] Slices of lists of lists

2014-03-28 Thread Jose Amoreira

Hello!
Here is something that surprised me and I still didn't get it.

If we want to store a matrix in pure python (no numpy), the first thing 
that comes to (my) mind is to use a list of lists, like the list l below:

In [1]: l=[
   ...:[11,12,13],
   ...:[21,22,23]
   ...:   ]

We can access individual components of this object in a simple, to be 
expected way:


In [2]: l[0][1], l[1][0]
Out[2]: (12, 21)

OK, that's fine. If we want to access individual rows of this matrix 
like object, the standard slice notation (on the second index) works as 
expected also:


In [3]: l[0][:]
Out[3]: [11, 12, 13]

In [4]: l[1][:]
Out[4]: [21, 22, 23]

Again, fine! But what if we want to access a particular row? My first 
guess was that standard slice notation on the first index would do it, 
but it doesn't! Instead, we get the rows again:


In [6]: l[:][0]
Out[6]: [11, 12, 13]

In [7]: l[:][1]
Out[7]: [21, 22, 23]

Why is this so?
Thanks,
Jose Amoreira
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Noob Question

2014-03-28 Thread Mark Lawrence

On 28/03/2014 01:17, Alan Gauld wrote:

On 27/03/14 21:01, Chris “Kwpolska” Warrick wrote:

On Mar 27, 2014 8:58 PM, "Alan Gauld" mailto:alan.ga...@btinternet.com>> wrote:
 >
 > On 27/03/14 06:43, Leo Nardo wrote:
 >>
 >> Im on windows 8 and i need to open a file called string1.py that
is on
 >> my desktop,
 >
 >
 > Thats your first problem. Its usually a bad idea to store your python
code on the desktop, because the desktop is a pain to find from a
command line.

Painful? How painful can `cd Desktop` be? Certainly less than `D:`
followed by `cd PythonProjects`…


Because the desktop is hardly ever anywhere near where the cmd prompt
lands you.

So cd desktop usually results in an error and typing the full path (even
with directory completion, Mark) is a royal pain because
you have to remember where it is. There is no ~ shortcut in Windows.


The point is you type it once and then rerun the command from the run 
prompt.  How can anything be easier?



On my system that means typing something like:

C:\Documents and Settings\alang\Desktop

or some such nonsense, complete with spaces in the path that add
to the pain.

Now I probably could use something like cd %HOMEPATH% to get to what
Windows laughingly considers my 'home' directory and then find it
from there but even so its not always obvious depending on the
windows version and the install options used. And of course if
the file happens to be on the "all users" Desktop looking in my
local Desktop doesn't help.

I find it much easier to know where my Python code lives from wherever I
happen to find myself in the labrynthian file system that is Windows.




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


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: [Tutor] Slices of lists of lists

2014-03-28 Thread Bob Williams
On 28/03/14 09:42, Jose Amoreira wrote:
> Hello!
> Here is something that surprised me and I still didn't get it.
> 
> If we want to store a matrix in pure python (no numpy), the first thing
> that comes to (my) mind is to use a list of lists, like the list l below:
> In [1]: l=[
>...:[11,12,13],
>...:[21,22,23]
>...:   ]
> 
> We can access individual components of this object in a simple, to be
> expected way:
> 
> In [2]: l[0][1], l[1][0]
> Out[2]: (12, 21)
> 
> OK, that's fine. If we want to access individual rows of this matrix
> like object, the standard slice notation (on the second index) works as
> expected also:
> 
> In [3]: l[0][:]
> Out[3]: [11, 12, 13]
> 
> In [4]: l[1][:]
> Out[4]: [21, 22, 23]
> 
> Again, fine! But what if we want to access a particular row? My first
> guess was that standard slice notation on the first index would do it,
> but it doesn't! Instead, we get the rows again:
> 
> In [6]: l[:][0]
> Out[6]: [11, 12, 13]
> 
> In [7]: l[:][1]
> Out[7]: [21, 22, 23]
> 

Jose,

Just for clarity, are you trying to access a particular *column* in your
last example?

Bob
-- 
Bob Williams
System:  Linux 3.11.10-7-desktop
Distro:  openSUSE 13.1 (x86_64) with KDE Development Platform: 4.12.3
Uptime:  06:00am up 4 days 19:51, 4 users, load average: 0.37, 0.18, 0.15
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Slices of lists of lists

2014-03-28 Thread Jose Amoreira




Jose,

Just for clarity, are you trying to access a particular *column* in your
last example?

Bob

Yes, that's it! I wanted to say "column", not "row" in my last example. 
Sorry about that! Thanks

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


Re: [Tutor] Help Noob Question

2014-03-28 Thread Alan Gauld

On 28/03/14 09:28, spir wrote:

On 03/28/2014 02:17 AM, Alan Gauld wrote:



you have to remember where it is. There is no ~ shortcut in Windows.
On my system that means typing something like:

C:\Documents and Settings\alang\Desktop


Can't you make a symlink pointing to Desktop? (in C:\ or anywhere else)


You could, and that would help a little. But the problem on Windows is 
that what appears on the Desktop *display* is an amalgam of (up to 3?) 
different folders in the file system. So just because you see an icon on 
the 'desktop' doesn't mean you actually know which folder it is in.


Secondly this correlation between desktop folder and desktop display 
means that's a bad place to store python files since every file you 
create will add to the clutter of icons on your display. In my python 
projects file I have over 100 small test files. That would be a

lot of icons messing up my screen.

So because of a combination of:
a) path complexity,
b) the disconnect between display and physical location and
c) the correlation between files and displayed icons
I recommend not using the desktop to store python files.

Of course everyone is free to ignore this recommendation,
it's just my experience/opinion. :-)


Well, all filesystems are labyrinthians


Yes but Windows is much more so because of the disconnect
between how it displays things in visual tools and how it
stores things on the disk (and the fact that it has multiple
disks often with partially duplicated file structures!)
Very few things wind up in one place only. For a user,
this is ameliorated by the use of Libraries to group
folders with similar content, but they only serve to
make life even harder for the programmer!

[Even worse is the iPad with its insistance on storing
files with the app that last worked on them. A moving
target indeed, even assuming you can find the files in
the first place. Stupid decision.]

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
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] Slices of lists of lists

2014-03-28 Thread Alan Gauld

On 28/03/14 09:42, Jose Amoreira wrote:

Hello!
Here is something that surprised me and I still didn't get it.

If we want to store a matrix in pure python (no numpy), the first thing
that comes to (my) mind is to use a list of lists, like the list l below:
In [1]: l=[
...:[11,12,13],
...:[21,22,23]
...:   ]



But remember this is not actually a two dimensional
table it is a sequential list of lists.
So Python sees it like:

> In [1]: l=[[11,12,13],[21,22,23]...]


We can access individual components of this object in a simple, to be
expected way:

In [2]: l[0][1], l[1][0]
Out[2]: (12, 21)

OK, that's fine. If we want to access individual rows of this matrix
like object, the standard slice notation (on the second index) works as
expected also:

In [3]: l[0][:]
Out[3]: [11, 12, 13]


The slice notation makes a copy. You don;t need that you can just use 
the first index:


In [3]: l[0]
Out[3]: [11, 12, 13]


Again, fine! But what if we want to access a particular row?


I assume you mean column?
That concept doesn't exist, instead you must ask Python
for the n-th element of every sublist.

That's not too hard using a list comprehension:

>>> [row[0] for row in l]
[11, 21]


guess was that standard slice notation on the first index would do it,


No, standard slices on the first element will give you sublists of the 
first row. Python doesn't have any concept of that second dimension, it 
only sees a list of items. The fact those items are themselves lists is 
purely incidental to the interpreter.



HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
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] Slices of lists of lists

2014-03-28 Thread Jose Amoreira

On 03/28/2014 10:32 AM, Alan Gauld wrote:


No, standard slices on the first element will give you sublists of the
first row. Python doesn't have any concept of that second dimension, it
only sees a list of items. The fact those items are themselves lists is
purely incidental to the interpreter.


HTH


Thanks, Alan. It was very helpful. I see it now:
l[:] is just a copy of the list itself. Then, l[:][k] == l[k].
Thanks again.
Jose
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Noob Question

2014-03-28 Thread Chris “Kwpolska” Warrick
On Fri, Mar 28, 2014 at 2:17 AM, Alan Gauld  wrote:
> On 27/03/14 21:01, Chris “Kwpolska” Warrick wrote:
>> Painful? How painful can `cd Desktop` be? Certainly less than `D:`
>> followed by `cd PythonProjects`…
>
>
> Because the desktop is hardly ever anywhere near where the cmd prompt lands
> you.

I just tested on my Windows 7 box.  It got me to C:\Users\Kwpolska.
`cd Desktop` is enough.
I also tested on a third-party’s XP box.  C:\Documents and
Settings\[username].  `cd Desktop`, too (though it’s
locale-dependent).

Does not look far from the desktop, does it?

Well, the only places where this might not work are Administrator
prompts in Vista-and-newer (which there is NO REAL REASON to use for
Python) — or possibly some ultra-crazy corporate environments (but you
should not be learning Python there — and if you are working there,
you know how to work with the command line/Windows/source control
already).  Or, of course, systems where you changed something and it
is not your profile directory — but it’s your doing.  So, it’s pretty
much the home directory everywhere you should be concerned with.

> you have to remember where it is. There is no ~ shortcut in Windows.
> On my system that means typing something like:
>
> C:\Documents and Settings\alang\Desktop

or just cd %USERPROFILE%.  Different drives would make you jump to
%HOMEDRIVE% and then to %HOMEPATH%.

>>
>>
>> Can't you make a symlink pointing to Desktop? (in C:\ or anywhere else)
>
>
> You could, and that would help a little. But the problem on Windows is that
> what appears on the Desktop *display* is an amalgam of (up to 3?) different
> folders in the file system. So just because you see an icon on the 'desktop'
> doesn't mean you actually know which folder it is in.

But, for user-created files, it always goes to %USERPROFILE%/Desktop.

> Secondly this correlation between desktop folder and desktop display means
> that's a bad place to store python files since every file you create will
> add to the clutter of icons on your display. In my python projects file I
> have over 100 small test files. That would be a
> lot of icons messing up my screen.

Create a folder on the desktop, or even in the home directory.  A much
nicer place than the drive root — and a much modern way to store it
(drive root sounds DOS-y)

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Noob Question

2014-03-28 Thread Walter Prins
Hi Leo,

On 27 March 2014 08:43, Leo Nardo  wrote:
> Im on windows 8 and i need to open a file called string1.py that is on my
> desktop, in both the interpreter and notepad++, so that i can work on it. I
> already have it open in notepad, but for the life of me cannot figure out
> how to open it in the interpreter. Invalid syntax is the error message when
> i type in""" python string1.py" into the interpreter! maybe a dumb
> question but i would appreciate the help for sure. thanks :)

I know a lot's been said already, but nothwithstanding, here's my
answer to your question(s):

You need to type

python string1.py

into a Windows command prompt, not directly into a running Python interpreter.

For that command to work as shown, at least 2 things need to be true:
1) The Python interpreter (python.exe) must be on the system PATH (so
the operating system will be able to locate it)
2) The file string1.py must be in the "Current Directory" (folder) of
the Windows command prompt. This is the path location displayed in the
prompt to the left of the cursor.

A simple way to open a command prompt with the current directory set
to a known location, is to open a Windows file explorer window, then
browse to the folder you'd like a command prompt in, then overtype the
address in the explorer window with "cmd" and press Enter.  This
little feature makes it trivial to open command prompts in any chosen
folder as needed. (Note: This feature is only available in Windows 7
and higher.)

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


Re: [Tutor] Slices of lists of lists

2014-03-28 Thread spir

On 03/28/2014 10:42 AM, Jose Amoreira wrote:

[...]  If we want to access individual rows of this matrix like
object, the standard slice notation (on the second index) works as expected 
also:

In [3]: l[0][:]
Out[3]: [11, 12, 13]

In [4]: l[1][:]
Out[4]: [21, 22, 23]

Again, fine!


No! You *made* here *copies* of the rows. To *get* the rows themselves as they 
are, just type:

l[index_of_row]

Also note the following: thinking in terms of row/column is very much 
misleading. The row number/index is actually the "vertical"(y or j) coordinate, 
and the column index is a horizontal coordinate... Thus, if you to think that 
way, speak of "columns & rows"! not the other way round. This means that, if you 
want yourself or a user to write down a matrix (or eg a game board or map), they 
would have to inverse their logic; or you would have to reverse the map (your 
other question).


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


Re: [Tutor] Help Noob Question

2014-03-28 Thread David Rock
* Chris “Kwpolska” Warrick  [2014-03-28 16:27]:
> 
> Create a folder on the desktop, or even in the home directory.  A much
> nicer place than the drive root — and a much modern way to store it
> (drive root sounds DOS-y)

I'll have to disagree with this statement. Dropping all your files in
you Desktop directory puts all the files ON the Desktop, which quickly
becomes a mess.  Regardless of whether it's a new directory at the base,
or a new directory under your User directory, you should at least have a
dedicated directory to put the files.  I'm not discussing the merits of
one place over the other, just that simple organization is a good thing.

Put it wherever you want, but at least keep it organized.  Dropping
everything in Desktop is not organized.

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


[Tutor] Writing to text files

2014-03-28 Thread Nathan Curnow (Year 10)
HU. HU. HU.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Noob Question

2014-03-28 Thread Alan Gauld

On 28/03/14 15:27, Chris “Kwpolska” Warrick wrote:

On Fri, Mar 28, 2014 at 2:17 AM, Alan Gauld  wrote:



Because the desktop is hardly ever anywhere near where the cmd prompt lands
you.


I just tested on my Windows 7 box.  It got me to C:\Users\Kwpolska.
`cd Desktop` is enough.
I also tested on a third-party’s XP box.  C:\Documents and
Settings\[username].  `cd Desktop`, too (though it’s
locale-dependent).

Does not look far from the desktop, does it?


True when you first open the DOS box, but not after you've been using it 
for a while. I usually find I've moved around several folders and even 
several disks.



Python) — or possibly some ultra-crazy corporate environments (but you
should not be learning Python there — and if you are working there,
you know how to work with the command line/Windows/source control
already).


Both are true for me, and a large part of why I wouldn't put stuff on 
the desktop. For example my desktop was made up of my personal desktop, 
the PC all-user desktop and the corporate shared desktop (only when 
connected to the corporate network). Knowing which files/icons

belonged to which location was a nightmare.


or just cd %USERPROFILE%.  Different drives would make you jump to
%HOMEDRIVE% and then to %HOMEPATH%.


Which is true for files I create but not for other users of the PC or 
for shared desktops. And its still a lot to type compared to Unix (~) or 
using a drive root.



Can't you make a symlink pointing to Desktop? (in C:\ or anywhere else)

You could, and that would help a little. But the problem on Windows is that
what appears on the Desktop *display* is an amalgam of (up to 3?) different
folders in the file system. So just because you see an icon on the 'desktop'
doesn't mean you actually know which folder it is in.


But, for user-created files, it always goes to %USERPROFILE%/Desktop.


But which user? It may not be me that created the file.
And I may have deliberately copied/saved it to one of
the shared desktops a long time ago and forgotten.


Create a folder on the desktop, or even in the home directory.


I agree a folder is more sensible and avoids the icon overkill but
the OP specifically had his *file* on the desktop.


nicer place than the drive root — and a much modern way to store it
(drive root sounds DOS-y)


I accept that but its still the shortest absolute path to type
on Windows! And if you are a programmer typing is what you wind
up doing a lot of!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
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] Writing to text files

2014-03-28 Thread Ben Finney
"Nathan Curnow (Year 10)" <13...@budehaven.cornwall.sch.uk> writes:

> HU. HU. HU.

Here's hoping you improve your communication skills during Year 10,
Nathan.

-- 
 \  “What we usually pray to God is not that His will be done, but |
  `\   that He approve ours.” —Helga Bergold Gross |
_o__)  |
Ben Finney

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


Re: [Tutor] while loop

2014-03-28 Thread Scott W Dunning

On Mar 28, 2014, at 9:54 PM, Scott W Dunning  wrote:

> Hello, I’m working on some practice exercises from my homework and I’m having 
> some issues figuring out what is wanted.  
> 
> We’re working with the while loop and this is what the question states;
> 
> Write a function print_n that prints a string n times using iteration.
> 
>   """Print the string `s`, `n` times. 
> 
> 
> This is also in the exercises and I’m not sure what it means and why it’s 
> there.
> 
> assert isinstance(s, str)
> assert isinstance(n, int)
> 
> 
> Any help is greatly appreciated!
> 
> Scott

This is what I have so far but I’m not really sure it’s what the excersise is 
asking for?

n = 5
def print_n(s, n):
   while n > 0:
   print s * n

print_n("hello", 10)


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


Re: [Tutor] while loop

2014-03-28 Thread Ben Finney
Scott W Dunning  writes:

> On Mar 28, 2014, at 9:54 PM, Scott W Dunning  wrote:
>
> > We’re working with the while loop and this is what the question states;
> > 
> > Write a function print_n that prints a string n times using iteration.
> This is what I have so far but I’m not really sure it’s what the
> excersise is asking for?

A good programming exercise will show an example input and the expected
output, to give an unambiguous test case. Does the homework have that?

If not, you're unfortunately left to your own interpretation of what the
requirements mean.

-- 
 \ “Truth would quickly cease to become stranger than fiction, |
  `\ once we got as used to it.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


[Tutor] while loop

2014-03-28 Thread Scott W Dunning
Hello, I’m working on some practice exercises from my homework and I’m having 
some issues figuring out what is wanted.  

We’re working with the while loop and this is what the question states;

Write a function print_n that prints a string n times using iteration.

"""Print the string `s`, `n` times. 


This is also in the exercises and I’m not sure what it means and why it’s there.

assert isinstance(s, str)
assert isinstance(n, int)


Any help is greatly appreciated!

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


Re: [Tutor] while loop

2014-03-28 Thread Jay Lozier


On 03/29/2014 01:18 AM, Scott W Dunning wrote:

On Mar 28, 2014, at 9:54 PM, Scott W Dunning  wrote:


Hello, I’m working on some practice exercises from my homework and I’m having 
some issues figuring out what is wanted.

We’re working with the while loop and this is what the question states;

Write a function print_n that prints a string n times using iteration.

"""Print the string `s`, `n` times.


This is also in the exercises and I’m not sure what it means and why it’s there.

assert isinstance(s, str)
assert isinstance(n, int)


Any help is greatly appreciated!

Scott

This is what I have so far but I’m not really sure it’s what the excersise is 
asking for?

n = 5
def print_n(s, n):
while n > 0:
print s * n

print_n("hello", 10)


Scott,

Are required to use a while loop?

Two ways to solve this, while loop and for in range loop

while loop
n = 5
s = 'some string'

def while_print(s, n):
index = o
while index < n:
print(index, s)
index += 1

def alternative_print(s, n):
for index in range(0, n):
print(index, s)

The while loop requires that a counter variable or some loop exit 
condition so you do not end up in an endless loop. This is a common 
problem with while loops in programming, not just Python. So, if there 
is alternative method of looping available, good programming practice is 
to avoid a while loop in any language. The for loop version 
automatically iterates over the range from 0 to n-1 (5 times). I 
included the index variable in the print to show the increase of the index.


The results for both:
0 some string
1 some string
2 some string
3 some string
4 some string

--
Jay Lozier
jsloz...@gmail.com

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