Re: [Tutor] Running a script in the background

2012-09-04 Thread Alan Gauld

On 04/09/12 01:26, Dwight Hutto wrote:


But each OS(BIOS handler) has a way of providing/accepting instructions
to the processor, which is constantly procedural. This has to have a
terminal at some point.


No it doesn't. Most OS do not run in a 'procedural' way (by which I 
assume you mean sequential?) Most are event driven and that often at the 
hardware level. The processor has an interrupt mechanism which causes a 
section of code to run. The section chosen is determined by the 
interrupt number and results in a jump to a predefined address.

The interrupts are driven by hardware events with no software control.
Some interrupts are pre-emptive - they will stop any current processing 
and take control, others will wait for current processing to finish.
The processor will also have a software interrupt mechanism which does 
the same thing but is driven by an INT call in the software.


Operating systems from CP/M and DOS onwards are driven by interrupts
at the kernel level they do not sit in some kind of giant event loop 
looking for things to process.



What is meant by behind a console, and running without a console, just a
window system, and a file set that deals with instructions/errors based
on BIOS input/output?


Again no, a terminal is an I/O mechanism. It reads input and displays 
output. The terminal does not process the commands it passes those to 
the program running inside it. Even the shell is not part of the 
Terminal, it just runs inside. And daemon programs do not use a terminal 
at all.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] multi processes or threads?

2012-09-04 Thread Alan Gauld

On 04/09/12 01:19, Dwight Hutto wrote:


I have no idea what all that means!
Nor how it relates to the OPs question.
 From the OP:

  I'm working on AI for a robot and because I'm not sure what direction


OK, I see that connection now.


Tell me Alan, what is threading within a CPU, coming from a higher level
language, that passes through a processor executing one instruction at
time from the instruction pointer, unless otherwise designed from
multiple instructions through separate cpu's(i.e. real thread commands)?


I'm still not certain what you mean here but I think you are referring 
to the time-slicing technique used by the OS to run multiple 
processes/threads on a single CPU?  The CPU (or core) doesn't understand 
the concept of threading that's a higher level concept
usually managed by the OS (although with multi-core CPUs increasingly 
done at hardware too).


The point of threading is to avoid programs blocking while still having 
valid work to do. In effect taking advantage of the multi-processing 
features of the OS to allow parts of a program to keep running when it 
would otherwise block while waiting for input or output to complete.
As such it will make the application more responsive and for bulk data 
processing run faster (with fewer wait states).


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] running more than one python program at the same time

2012-09-04 Thread Oscar Benjamin
Hi Ben,

It's best if you can avoid top-posting and put your responses in between
the appropriate parts of the message you are replying to like I have below:

On 4 September 2012 02:53, Benjamin Fishbein  wrote:

> I used Python Launcher and it opened it in the terminal.
> Ben
>
> On Sep 3, 2012, at 2:50 PM, Oscar Benjamin wrote:
>
> > On Mon, 03 Sep 2012 18:55:43 +0100, Alan Gauld <
> alan.ga...@btinternet.com> wrote:
> >> On 03/09/12 16:01, Benjamin Fishbein wrote:
> >> > Hi. I started running the program in the terminal rather than
> > IDLE. It
> >> > works, and I can run several programs at the same time. The
> > problem is
> >> > that when the program is finished running, it prints:
> >> > exit status: 0
> >> > logout
> >> >
> >> > [Process completed]
> >
> > What do you mean when you say you ran the program in the terminal? Do
> you mean that you opened a terminal window and then typed 'python
> myprog.py'? Or did you click on the python file and choose 'run in
> terminal' or similar? That output looks to me like what happens on OSX when
> a terminal window is open but the shell has been closed.
>

So you were using the python launcher on the dock? I guess you are using
OSX, then (it's good to provide this kind of information).

The reason you're not seeing any output is probably because you're not
printing it. If your program has a variable called 'total' that you would
like to see the value of simply put a line like 'print(total)' at the end
of your script. Then you should see the output.



>  >
> > I think the instruction to run in a terminal should look like:
> > 1) open the terminal (how to do this depends on your OS).
> > 2) type 'cd /path/to/my/script/folder' and then hit enter.
> > 3) type 'python script.py' and then hit enter.
>

Have you tried the instructions above. Assuming you're using OSX you can do
step 1 by hitting cmd-space to open spotlight. Then you type 'terminal' and
hit enter and you will have a terminal window.

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


Re: [Tutor] Running a script in the background

2012-09-04 Thread eryksun
On Mon, Sep 3, 2012 at 10:21 PM, Dwight Hutto  wrote:
> What's wrong with:
>
> But each OS(BIOS handler) has a way of providing/accepting instructions to
> the processor, which is constantly procedural. This has to have a terminal
> at some point.

What do you mean by 'terminal' in this context? A terminal is a device
(possibly virtual) for entering data and displaying output from a
computer.

cron isn't scheduling active processes/threads like the kernel does.
Every minute, it checks a job table and possibly starts one or more
programs. This is an efficient way to schedule a large number of
programs to run at various times throughout the day, week, and month.
Otherwise all of these programs would need to have at least a stub
that runs as a daemon, wasting memory and CPU resources needlessly.

Scheduling processes is an entirely different domain. In a preemptive
multitasking system, it's up to the kernel to schedule access to the
CPU. Each process (or thread on some systems) is assigned a quantum of
ticks. The ticks are based on a hardware timer. Periodically (e.g. 10
milliseconds) this timer triggers a hardware interrupt that enables
the kernel to preempt the current thread. The kernel schedules the
next (possibly the same) process to run, based on a priority scheme,
out of the pool of ready processes.

Preempting a running process requires a context switch, i.e. the
process control block (e.g. PID, priority, execution state such as
running/ready/waiting, CPU number/registers/flags, virtual memory,
signal handlers, I/O, credentials, accounting, etc) has to be saved on
the current stack. Then the PCB of the next process is loaded; the CPU
state is restored; and execution resumes seamlessly.

Here's the task_struct used by the Linux scheduler (lines 1235-1593):

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/sched.h#l1235

> What is meant by behind a console, and running without a console, just a
> window system, and a file set that deals with instructions/errors based on
> BIOS input/output?

Windows NT typically boots without a console. It doesn't have virtual
terminals, but you can run console programs in a Win32 console managed
by the Client/Server Runtime Subsystem (csrss.exe)

In contrast, Linux boots in console mode. Typically it maps the
"console" (boot parameter) to the current virtual terminal (i.e.
/dev/tty0), but it could also be a dumb terminal or modem. It creates
several virtual terminals depending on the system configuration.
Debian has tty's 1-63 and runs getty on tty 1-6 to allow text-mode
logins and an Xorg display manager (e.g. lightdm) on tty7 for logging
in to a graphical desktop environment (e.g. xfce4).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread eryksun
On Mon, Sep 3, 2012 at 9:57 PM, Garry Willgoose
 wrote:
> I want to put a shortcut onto the desktop in windows (XP and later) in
>
> AttributeError: function 'CreateSymbolicLinkW' not found

A simple search for "msdn CreateSymbolicLink" leads to the following page:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363866.aspx

Scroll down to the requirements, and you'll see that
CreateSymbolicLink was added to Kernel32 (and NTFS) in Windows Vista
(NT 6.x). Kernel32 in Windows XP (NT 5.x) doesn't have that function;
hence the AttributeError.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 02:57, Garry Willgoose  wrote:

> I want to put a shortcut onto the desktop in windows (XP and later) in
> Python 2.6 or later. In Unix its easy using os.symlink but I can't find
> anything equivalent for windows. My searches on the web led me to the code
> below but the code returns the error
>
> AttributeError: function 'CreateSymbolicLinkW' not found
>
> so does anybody have any suggestions?
>

Are you really trying to create a symbolic link? Note that this is not the
same thing as a 'shortcut' in Windows. If you say why you want the shortcut
someone may be able to help you find another way of doing what you want.

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


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread Walter Prins
Hi,

On 4 September 2012 02:57, Garry Willgoose
 wrote:
> I want to put a shortcut onto the desktop in windows (XP and later) in Python 
> 2.6 or later. In Unix its easy using os.symlink but I can't find anything 
> equivalent for windows. My searches on the web led me to the code below but 
> the code returns the error
>
> AttributeError: function 'CreateSymbolicLinkW' not found
> so does anybody have any suggestions?

IIRC and as implied by other responses so far, "Symbolic Links" are an
NTFS feature only relatively recently added to NTFS.  Creating a
Symbolic Link (whether on Windows or elsewhere) is not the same as
creating a "Shortcut" in Windows, even though they can in some
contexts (e.g. a GUI desktop environment) be used to fulfil the same
role.  Anyway, to be backwards compatible with Win XP you should be
creating a "Shortcut", more properly known as a "Shell link".  See
here:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891%28v=vs.85%29.aspx

Basically you need to use the IShellLink COM interface to create the
link.  You can use PythonCOM to do this (not sure if you'll be happy
about adding a dependency on COM to your application though), either
way, here's a presentation that also mentions IShellLink (note it's a
bit old so make allowances for the age):
http://starship.python.net/~skippy/conferences/tools99/html/ppframe.htm

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


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread Garry Willgoose
Oscar,

I actually just want the functionality of a shortcut so that I can put an icon 
on the desktop. symlink allows that in Unix (and a few other capabilities that 
I'm not that intersted in) and just want something equivalent to the menu item 
for making a shortcut in Windows. 

> On 4 September 2012 02:57, Garry Willgoose  
> wrote:
> I want to put a shortcut onto the desktop in windows (XP and later) in Python 
> 2.6 or later. In Unix its easy using os.symlink but I can't find anything 
> equivalent for windows. My searches on the web led me to the code below but 
> the code returns the error
> 
> AttributeError: function 'CreateSymbolicLinkW' not found
> 
> so does anybody have any suggestions?
> 
> Are you really trying to create a symbolic link? Note that this is not the 
> same thing as a 'shortcut' in Windows. If you say why you want the shortcut 
> someone may be able to help you find another way of doing what you want.
> 
> Oscar


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


Re: [Tutor] running more than one python program at the same time

2012-09-04 Thread Wayne Werner

On Mon, 3 Sep 2012, William R. Wing (Bill Wing) wrote:

junk = raw_input("Yes Master?")


You don't even need the 'junk' bit:

raw_input("Yes Master?")

Will run just fine.

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


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread Wayne Werner

On Tue, 4 Sep 2012, Garry Willgoose wrote:


Oscar,

I actually just want the functionality of a shortcut so that I can put an
icon on the desktop. symlink allows that in Unix (and a few other
capabilities that I'm not that intersted in) and just want something
equivalent to the menu item for making a shortcut in Windows. 


At least in Windows 7+, you can use the mklink command (as administrator):

import subprocess
subprocess.check_call(['mklink',
   '/D', #Use /H for a hard link
   '\users\yourname\desktop\yourfile.txt',
   '\path\to\yourfile.txt'])

HTH,
Wayne___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread Walter Prins
Hi,

On 4 September 2012 15:44, Wayne Werner  wrote:
>> I actually just want the functionality of a shortcut so that I can put an
>> icon on the desktop. symlink allows that in Unix (and a few other
>> capabilities that I'm not that intersted in) and just want something
>> equivalent to the menu item for making a shortcut in Windows.
>
>
> At least in Windows 7+, you can use the mklink command (as administrator):
>
> import subprocess
> subprocess.check_call(['mklink',
>'/D', #Use /H for a hard link
>'\users\yourname\desktop\yourfile.txt',
>'\path\to\yourfile.txt'])
>
> HTH,
> Wayne

Yes, but as already noted symbolic links are a newish feature that is
not available on older OS's, so the original poster probably wants to
look at API's to create actual shortcut's given that he's targeting
WinXP etc.

Regards

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


[Tutor] help me decide

2012-09-04 Thread Matthew Ngaha
hey guys as i program more, i think of silly questions i would like
answers to. if anyone doesnt mind entertaining my question, please do
answer:) I have just about finished my beginner tutorial, just a few
exercises left. i feel confident using Python now but im still not
sure which direction i want to go in. I would at some point like to
learn how to use GUIs and a web Framework(Django). But i don't know
which of the 2 to start out with.

a) IF you happen to have used both, which one fills you with joy and
is more fun for you to program with, GUI programming, or web related /
Framework programming?

b) which was easier and less complex for you to learn? or should i say
had a lower learning curve? i ask this because the sooner i get an
understanding of one, i can maybe give the other one a go. But if it's
too hard i usually give 100% to it and never try learning anything
else until it computes.

my tutorial had a small section on tkinter. I have now looked for some
tutorials and noticed Python tutorials on both tkinter and Tk. As i
understand they are not the same thing but tkinter is like the
interface of Tk? my question is:

c) which tutorial would be better to study, Tkinter or Tk? and what
exactly is the difference? why do they have separate tutorials?

i looked at some pyQT articles, but its coding looks less organised
than Tkinter.

d) is this true? is Tkinter a lot more straight forward and Python friendly?

e) Does pyQT have grids (rows and columns) to place your widgets on
like Tkinter, or do you have to use x and y axis to position widgets
etc..?

Before i try to learn either, GUIs or a web Framework, i was looking
into maybe getting a deeper understanding of OOP. my tutorial only
covered it briefly.

f) would this be a good idea tackling OOP next before the other 2, or
is this a skill you master with more programming experience?

ok my last question is not so important:) im just curious as i grow
more fond of programming. well i keep reading Python is an all-purpose
general programming language(web frameworks, desktop apps,
science/maths etc..). I notice Java has similar features so should
also be considered an all-purpose general programming language. my
question is:

g) not a comparison in 1 specific area, but which language is better
or more suited to all around all-purpose quality.

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


Re: [Tutor] help me decide

2012-09-04 Thread leam hall
Matthew,

Program what is fun for you. I prefer PHP for web work but I'm learning
Python for my day job. Python provides a wider range of abilities but PHP
is more "fun" for me. If Python GUIs are fun, then do that. The more you
enjoy the topic the more reason you will have to learn more and more. I
doubt you will exhaust Python's capabilities any time soon.

Python or Java? For me it's Python. The only real Java advantage might be
Android programming.

Leam


-- 
Mind on a Mission 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help me decide

2012-09-04 Thread Matthew Ngaha
sorry wrong i didnt send mail right.

hey i didnt explain it properly, i wasn't asking what language to use
 or learn. I am only going to be using Python. I meant whic area to
 study on 1st, GUI programing e.g Tkinter or Programming with a web
 framwork e.g Django.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help me decide

2012-09-04 Thread Matthew Ngaha
hey you didnt read my question:( i dont enjoy either because i have no
experience with them. so im asking questions about peoples personal
experiences with the 2 areas which can give me further information to
research on.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor