Re: [Tutor] New to Programming

2010-06-14 Thread cristeto1981



Dave Angel wrote:
> 
> Kaushal Shriyan wrote:
>> Hi,
>>
>> I am absolutely new to programming language. Dont have any programming
>> experience. Can some one guide me please. is python a good start for
>> novice.
>>
>> Thanks,
>>
>> Kaushal
>>
>>   
> Like nearly all questions, the answer is "it depends."
> 
> Mainly, it depends on what your goal is.  In my case, I made my living 
> with programming, for many years.  And in the process, learned and used 
> about 35 languages, plus a few more for fun.  I wish I had discovered 
> Python much earlier, though it couldn't have been my first, since it 
> wasn't around.  But it'd have been much better than Fortran was, for 
> learning.
> 
> So tell us about your goals.  Abstract knowledge, console utilities, gui 
> development, games, web development, networking communication, ...
> 
> Next, you might want to evaluate what you already know.  There are a lot 
> of non-programming things that a programmer needs to understand.  If you 
> already know many of them, that's a big head start.  If you already know 
> how to administer a Linux system, you're already a programmer and didn't 
> know it.  If you write complex formulas for Excel, you're a programmer.  
> If you already know modus ponens, and understand what a contrapositive 
> is, you've got a head start towards logic (neither is a programming 
> subject, just a start towards logical thinking).  If you've worked on a 
> large document, and kept backups of  incremental versions, so you could 
> rework the current version based on earlier ones, that's a plus.  If you 
> know why a file's timestamp might change when you copy it from hard disk 
> to a USB drive and back again, you've got a head start.  If you know why 
> it might have a different timestamp when you look at it six months from 
> now without changing it, you've got a head start.
> 
> If you're using Windows and never used a command prompt, you have a ways 
> to go.  If you don't know what a file really is, or how directories are 
> organized, you have a ways to go.  And if you think a computer is 
> intelligent, you have a long way to go.
> 
> Python is a powerful tool.  But if you're totally new to programming, it 
> can also be daunting.  And most people have no idea how easy some 
> programs are, nor how hard some other programs are, to build.
> 
> In any case, some of the things recommending Python as a first language
> are:
>1) an interactive interpreter - you can experiment, trivially
>2) very fast turnaround, from the time you make a change, till you 
> can see how it works.  This can be true even for large programs
>3) this mailing list
> 
> DaveA
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
Thanks for this thread. It really helps. Those links were very informative.
:)

-
[url=http://crosspromotion.wizard4u.com/]joint ventures[/url]

-- 
View this message in context: 
http://old.nabble.com/-Tutor--New-to-Programming-tp28863541p28878181.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] large file

2010-06-14 Thread cristeto1981



Alan Gauld wrote:
> 
> 
> "Hs Hs"  wrote
> 
>> I have a very large file 15Gb.
> 
>> Every two lines are part of one readgroup.
>> I want to add two variables to every line.
> 
>> HWUSI-EAS1211_0001:1:1:977:20764#0   RG:Z:2301
>> HWUSI-EAS1211_0001:1:1:977:20764#0RG:Z:2302
>> ...
>> Since I cannot read the entire file, I wanted to cat the file
> 
> What makes you think you cannot read the entire file?
> 
>> something like this:
>>
>> cat myfile  | python myscript.py > myfile.sam
> 
> How does that help over Python reading the file line by line?
> 
>> I do not know how to execute my logic after I read the line, 
>> althought I tried:
> 
>> while True:
>>second = raw_input()
>>x =  second.split('\t')
> 
> Why are you splitting theline? You only need to append
> data to the end of the line...
> 
>> Could someone help me here either what I want to do.
> 
> In pseudo code:
> 
> open input and ouput files
> read the first 14 lines from input
> oddLine = True
> while True:
>  read line from input
>  if oddLine:
> append odd data
>  else
>append evenData
>  write line to output file
>  oddLine = not oddLine
> 
> You probably want a try/except in there to catch the end of file.
> 
> 
> This is not very different from the menu example in the file
> handling topic of my tutorial...
> 
> HTH
> 
> -- 
> Alan Gauld
> 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
> 
> 
Thanks for this thread. This is very helful. I'm learning a lot from you
guys. :)

-
[url=http://crosspromotion.wizard4u.com/]joint ventures[/url]

-- 
View this message in context: 
http://old.nabble.com/-Tutor--large-file-tp28874185p28878191.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] Better construct?

2010-06-14 Thread Advertising Department

Many thanks to all,

 repeat WHILE
is exactly what I needed.

I got BASIC stuck in my head. GOTO line# YUCK!


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


Re: [Tutor] Better construct?

2010-06-14 Thread Alan Gauld


"Advertising Department"  wrote


 repeat WHILE
is exactly what I needed.

I got BASIC stuck in my head. GOTO line# YUCK!


BASIC has a WHILE/WEND construct too :-)
Even GW Basic supported that.

Alan G.

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


[Tutor] Structuring a class

2010-06-14 Thread Lang Hurst
I'm trying to figure out how to deal with data which will look something 
like:


   Student:Bob Hurley
   ID: 123456
   Period:4
   Grad_class: 2012
   Credits:
  Algebra C (20P)
Chapter 1
 Date: September 14, 2010
 Grade: 87
 Credits:1.5
 Notes: Probably cheated on final.  Really watch on 
next quiz/test.

Chapter 2
 Date: October 31, 2010
 .
 .   **and so on**
 .
  Consumer Math (24G)
Module 2
 .
 .   **more information like above**
 .


So, I just figured that I would have a couple of nested dictionaries.

   bob = Student('123456','Bob Hurley')
   bob.period = 4
   bob.grad_class = 2010
   bob['credits']['Algebra C (20P)']={'Chapter 1':{'Date':'September 
12, 2010', 'Grade':'87', **and so on**}}


This works, for the most part, from the command line.  So I decided to 
set up a class and see if I could work it from that standpoint (I'm 
doing this to scratch an itch, and try to learn).  My preliminary class 
looks like:


   class Student:
   def __init__(self, ident=' ', name=' ', period=' ', grad_class=' 
', subject=' ', notes=' ', credit=' '):

   self.name = name
   self.ident = ident
   self.period = period
   self.notes = notes
   self.grad_class = grad_class
#  self.credit = {{}}<--- BAD
   self.credit = {}

I'm sure that someone will enlighten me as to where my poor coding 
skills are especially weak.  It's the last line there (self.credit...) 
which I can't figure out.  The credits may be in any of about 30 
different subjects (teaching at a continuation high school makes for 
interesting times).


If I don't set it to anything, ie, like it is, I get an error

   Stud instance has no attribute '__getitem__'

If I try to leave it available for adding to somewhat dynamically, I get 
a 'wtf' from python.


Sorry for the novel, I'm just wondering if someone would set me 
straight.  Should I even use a class?  If so, how do I set up a class 
item which let's me add dictionaries to it?  Thanks.


-Lang



--
There are no stupid questions, just stupid people.

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


Re: [Tutor] Structuring a class

2010-06-14 Thread bob gailer

On 6/14/2010 8:08 PM, Lang Hurst wrote:
I'm trying to figure out how to deal with data which will look 
something like:


   Student:Bob Hurley
   ID: 123456
   Period:4
   Grad_class: 2012
   Credits:
  Algebra C (20P)
Chapter 1
 Date: September 14, 2010
 Grade: 87
 Credits:1.5
 Notes: Probably cheated on final.  Really watch on 
next quiz/test.

Chapter 2
 Date: October 31, 2010
 .
 .   **and so on**
 .
  Consumer Math (24G)
Module 2
 .
 .   **more information like above**
 .

Before deciding on data structures I suggest you give the big picture. 
Where will data come from? What do you plan to do with it?


Often a case like this is better handled using a relational database. 
Python happens to come with the sqlite3 module which makes database work 
quite easy.




So, I just figured that I would have a couple of nested dictionaries.

   bob = Student('123456','Bob Hurley')
   bob.period = 4
   bob.grad_class = 2010
   bob['credits']['Algebra C (20P)']={'Chapter 1':{'Date':'September 
12, 2010', 'Grade':'87', **and so on**}}


This works, for the most part, from the command line.  So I decided to 
set up a class and see if I could work it from that standpoint (I'm 
doing this to scratch an itch, and try to learn).  My preliminary 
class looks like:


   class Student:
   def __init__(self, ident=' ', name=' ', period=' ', 
grad_class=' ', subject=' ', notes=' ', credit=' '):

   self.name = name
   self.ident = ident
   self.period = period
   self.notes = notes
   self.grad_class = grad_class
#  self.credit = {{}} <--- BAD
   self.credit = {}

I'm sure that someone will enlighten me as to where my poor coding 
skills are especially weak.  It's the last line there (self.credit...) 
which I can't figure out.  The credits may be in any of about 30 
different subjects (teaching at a continuation high school makes for 
interesting times).


You should define a class for Credit, which will hold the credit 
attributes, just like you did for Student. Then assign instances of 
Credit to entries in self.credit.


If I don't set it to anything, ie, like it is, I get an error

   Stud instance has no attribute '__getitem__'

If I try to leave it available for adding to somewhat dynamically, I 
get a 'wtf' from python.


Sorry I don't understand these. It is a good idea to post full 
tracebacks and the code that raises the exception.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Structuring a class

2010-06-14 Thread Lang Hurst


bob gailer wrote:





Often a case like this is better handled using a relational database. 
Python happens to come with the sqlite3 module which makes database 
work quite easy.






You should define a class for Credit, which will hold the credit 
attributes, just like you did for Student. Then assign instances of 
Credit to entries in self.credit.




Last time I did anything with python, it was years ago on a web 
application and I ended up using gadfly as a database.  I did not know 
that sqlite3 came as a module for python.  That just made it much, much 
easier.  I've done much more work with databases.  Thank you.  I figured 
that I was probably missing something obvious.


-Lang

--
There are no stupid questions, just stupid people.

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


Re: [Tutor] large file

2010-06-14 Thread Eduardo Vieira
> Thanks for this thread. This is very helful. I'm learning a lot from you
> guys. :)
>
> -
> [url=http://crosspromotion.wizard4u.com/]joint ventures[/url]
>
> --
> View this message in context: 
> http://old.nabble.com/-Tutor--large-file-tp28874185p28878191.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
I think this subscriber is just spamming. Two post with the same text.

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