This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2011-09-16 17:47:21

fire219
Scratcher
Registered: 2008-02-07
Posts: 1000+

Re: Various Areas of Python

wulfmaster wrote:

don't you need to import the time plugin?

Yea, just found that out.  lol


http://bluetetrarpg.x10.mx/usercard/img.php?name=fire219

Offline

 

#27 2011-09-16 18:15:27

fire219
Scratcher
Registered: 2008-02-07
Posts: 1000+

Re: Various Areas of Python

OK, this makes no sense....

This code:

Code:

import http.client
import time
userchoice = str(input("Select a website: "))
load = http.client.HTTPConnection(userchoice)
load.request("GET", "/")
r1 = load.getresponse()
print(r1.read())
time.sleep (5000)

It works like a dream in IDLE, but gives me a flurry of traceback errors that go by too fast to read in regular Python. Any help, please?


http://bluetetrarpg.x10.mx/usercard/img.php?name=fire219

Offline

 

#28 2011-09-17 09:26:29

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

nickbrickmaster wrote:

Hey max, I was wondering if you knew anything about the "Pickle" way of saving files in python. In my program, it's supposed to save a list, but when it does the pickle.dump(), I get an error saying

Error wrote:

Traceback (most recent call last):
  File "Z:\python_programs\Textgame1", line 124, in <module>
    pickle.dump(savelist, Name + "textventure.txt")
  File "C:\Python26\lib\pickle.py", line 1362, in dump
    Pickler(file, protocol).dump(obj)
  File "C:\Python26\lib\pickle.py", line 203, in __init__
    self.write = file.write
AttributeError: 'str' object has no attribute 'write'

Can you help? Much thanky.

Hm.  It would help to know what your program was, but I can do my best.  First of all, start the file by writing 'import picke'.  Second of all, never do '.write', I think.  Always '.dump'.  Third, you can only pickle lists.  Fourth, always end the file name of pickles in '.dat'.  Without knowledge of what you actually have, that's all I can do.

Offline

 

#29 2011-09-17 09:39:04

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

fire219 wrote:

OK, this makes no sense....

This code:

Code:

import http.client
import time
userchoice = str(input("Select a website: "))
load = http.client.HTTPConnection(userchoice)
load.request("GET", "/")
r1 = load.getresponse()
print(r1.read())
time.sleep (5000)

It works like a dream in IDLE, but gives me a flurry of traceback errors that go by too fast to read in regular Python. Any help, please?

Works perfectly for me (or would, if it didn't keep keep printing the HTML of the websites); no error message.

Last edited by maxskywalker (2011-09-17 09:41:24)

Offline

 

#30 2011-09-17 15:48:16

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

So anyway...

Offline

 

#31 2011-09-17 16:37:21

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: Various Areas of Python

maxskywalker wrote:

nickbrickmaster wrote:

Hey max, I was wondering if you knew anything about the "Pickle" way of saving files in python. In my program, it's supposed to save a list, but when it does the pickle.dump(), I get an error saying

Error wrote:

Traceback (most recent call last):
  File "Z:\python_programs\Textgame1", line 124, in <module>
    pickle.dump(savelist, Name + "textventure.txt")
  File "C:\Python26\lib\pickle.py", line 1362, in dump
    Pickler(file, protocol).dump(obj)
  File "C:\Python26\lib\pickle.py", line 203, in __init__
    self.write = file.write
AttributeError: 'str' object has no attribute 'write'

Can you help? Much thanky.

Hm.  It would help to know what your program was, but I can do my best.  First of all, start the file by writing 'import picke'.  Second of all, never do '.write', I think.  Always '.dump'.  Third, you can only pickle lists.  Fourth, always end the file name of pickles in '.dat'.  Without knowledge of what you actually have, that's all I can do.

Thanks. I did import pickle, but I was trying to save it as a .txt. Thanks!
EDIT: Not helping. Do I have an outdated version or something? I'm using 2.6.

Last edited by nickbrickmaster (2011-09-17 16:41:40)


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#32 2011-09-18 16:31:50

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

nickbrickmaster wrote:

maxskywalker wrote:

nickbrickmaster wrote:

Hey max, I was wondering if you knew anything about the "Pickle" way of saving files in python. In my program, it's supposed to save a list, but when it does the pickle.dump(), I get an error saying

Can you help? Much thanky.

Hm.  It would help to know what your program was, but I can do my best.  First of all, start the file by writing 'import picke'.  Second of all, never do '.write', I think.  Always '.dump'.  Third, you can only pickle lists.  Fourth, always end the file name of pickles in '.dat'.  Without knowledge of what you actually have, that's all I can do.

Thanks. I did import pickle, but I was trying to save it as a .txt. Thanks!
EDIT: Not helping. Do I have an outdated version or something? I'm using 2.6.

Oh.  I use Python 3 (3.1.1 and 3.1.4- different computers).  I would have learned 2.6, but the only book I could find was on 3.

Offline

 

#33 2011-09-18 16:36:04

wulfmaster
Scratcher
Registered: 2011-04-23
Posts: 500+

Re: Various Areas of Python

fire219 wrote:

wulfmaster wrote:

don't you need to import the time plugin?

Yea, just found that out.  lol

lol  Python is easy for me.  I like the modules though, they make is so organised!  smile


Social Connections - Bringing communities close together! http://cyberkidscountry.com/ip.php

Offline

 

#34 2011-09-18 18:35:22

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

wulfmaster wrote:

fire219 wrote:

wulfmaster wrote:

don't you need to import the time plugin?

Yea, just found that out.  lol

lol  Python is easy for me.  I like the modules though, they make is so organised!  smile

And look better than using namespaces in C++.

Offline

 

#35 2011-09-19 11:18:14

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Various Areas of Python

maxskywalker wrote:

1.  Why use objects to indirectly access methods instead of just directly accessing static methods?

Because it uses less memory and allows run-time flexibility of defining functions, not like when it gets compiled.

maxskywalker wrote:

4.  How does Python/PyGame make .exe files instead of .py files (imagine something like WoW or CoD where you can just right-click on the program and choose 'edit in IDLE' to hack the entire game).

freezing

maxskywalker wrote:

5.  How do you make a project using multiple programming languages in the same project (I heard about a few things that did like Ruby and Perl or something like that some years back)?

JYthon for Java and this for C/C++ are ways. This is also very helpful.

PS I love this site!

Offline

 

#36 2011-09-19 18:48:35

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

Well then, anyone got an answer for the riddle?  This Is The Hint.

Offline

 

#37 2011-09-20 11:40:40

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

Anyone?

Offline

 

#38 2011-09-26 22:00:11

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: Various Areas of Python

Is there a way I can publish games online from python?[/stupid question]


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#39 2011-09-27 07:14:09

Vurb
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: Various Areas of Python

nickbrickmaster wrote:

Is there a way I can publish games online from python?[/stupid question]

Nope, even if you compile it to .exe with py2exe (the python IDE itself doesn't have a compiler linked), you can't really embed it anywhere, unless you put it up for download.


To the OP, looks like you have all your questions but I can tell you Python is an easy language and you shouldn't take it too seriously if you're planning to actually learn programming. Also you're not all that much proficient if you haven't even learned classes yet, that's like saying I know C++ when all of my programs are just gotos and if statements.

Last edited by Vurb (2011-09-27 07:19:15)

Offline

 

#40 2011-09-27 08:50:37

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

Vurb wrote:

nickbrickmaster wrote:

Is there a way I can publish games online from python?[/stupid question]

Nope, even if you compile it to .exe with py2exe (the python IDE itself doesn't have a compiler linked), you can't really embed it anywhere, unless you put it up for download.


To the OP, looks like you have all your questions but I can tell you Python is an easy language and you shouldn't take it too seriously if you're planning to actually learn programming. Also you're not all that much proficient if you haven't even learned classes yet, that's like saying I know C++ when all of my programs are just gotos and if statements.

I actually do a good bit of C++.  I'm just not particularly fond of classes.  I feel like functions seem more logical to use, unless you're writing in Java (I do a tiny bit of that) or something, where classes are mandatory.

Offline

 

#41 2011-09-27 11:27:08

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: Various Areas of Python

Vurb wrote:

nickbrickmaster wrote:

Is there a way I can publish games online from python?[/stupid question]

Nope, even if you compile it to .exe with py2exe (the python IDE itself doesn't have a compiler linked), you can't really embed it anywhere, unless you put it up for download

thx. and if you were talking to me, im just learning.


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#42 2011-09-30 20:57:04

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

Just added 9.

Offline

 

#43 2011-09-30 21:12:03

flamekyle
Scratcher
Registered: 2011-03-18
Posts: 1000+

Re: Various Areas of Python

I should try Python, ...maybe


http://prodegebanners.sitegrip.com/images/swagbucks-173x63Alt5.jpg

Offline

 

#44 2011-10-01 20:10:07

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

flamekyle wrote:

I should try Python, ...maybe

Um, okay.  I personally like it.  And besides, it's got Ogre3D available for it.

Offline

 

#45 2011-10-02 10:19:28

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

. . .

Offline

 

#46 2011-10-02 12:54:02

Vurb
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: Various Areas of Python

maxskywalker wrote:

Vurb wrote:

nickbrickmaster wrote:

Is there a way I can publish games online from python?[/stupid question]

Nope, even if you compile it to .exe with py2exe (the python IDE itself doesn't have a compiler linked), you can't really embed it anywhere, unless you put it up for download.


To the OP, looks like you have all your questions but I can tell you Python is an easy language and you shouldn't take it too seriously if you're planning to actually learn programming. Also you're not all that much proficient if you haven't even learned classes yet, that's like saying I know C++ when all of my programs are just gotos and if statements.

I actually do a good bit of C++.  I'm just not particularly fond of classes.  I feel like functions seem more logical to use, unless you're writing in Java (I do a tiny bit of that) or something, where classes are mandatory.

A large deal of programming is about efficiency, and classes definitely add to that. I bet you know that classes can contain functions, too? I didn't use that much object-oriented programming as I was starting out, but it just became more simple when my programs reached over 1500 lines of code.

Offline

 

#47 2011-10-02 13:25:15

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

Vurb wrote:

maxskywalker wrote:

Vurb wrote:


Nope, even if you compile it to .exe with py2exe (the python IDE itself doesn't have a compiler linked), you can't really embed it anywhere, unless you put it up for download.


To the OP, looks like you have all your questions but I can tell you Python is an easy language and you shouldn't take it too seriously if you're planning to actually learn programming. Also you're not all that much proficient if you haven't even learned classes yet, that's like saying I know C++ when all of my programs are just gotos and if statements.

I actually do a good bit of C++.  I'm just not particularly fond of classes.  I feel like functions seem more logical to use, unless you're writing in Java (I do a tiny bit of that) or something, where classes are mandatory.

A large deal of programming is about efficiency, and classes definitely add to that. I bet you know that classes can contain functions, too? I didn't use that much object-oriented programming as I was starting out, but it just became more simple when my programs reached over 1500 lines of code.

Yeah, I know.  I just don't get what makes it better to say, for example, 'g.say()' instead of 'say()'.  But yeah, I guess so.

Offline

 

#48 2011-10-02 13:29:35

Vurb
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: Various Areas of Python

maxskywalker wrote:

Vurb wrote:

maxskywalker wrote:

I actually do a good bit of C++.  I'm just not particularly fond of classes.  I feel like functions seem more logical to use, unless you're writing in Java (I do a tiny bit of that) or something, where classes are mandatory.

A large deal of programming is about efficiency, and classes definitely add to that. I bet you know that classes can contain functions, too? I didn't use that much object-oriented programming as I was starting out, but it just became more simple when my programs reached over 1500 lines of code.

Yeah, I know.  I just don't get what makes it better to say, for example, 'g.say()' instead of 'say()'.  But yeah, I guess so.

Who builds classes just for a say()? Your example of classes is like this example of functions - "who needs funcprint(this) instead of cout  < this?

Last edited by Vurb (2011-10-02 13:31:11)

Offline

 

#49 2011-10-02 14:17:25

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

Vurb wrote:

maxskywalker wrote:

Vurb wrote:


A large deal of programming is about efficiency, and classes definitely add to that. I bet you know that classes can contain functions, too? I didn't use that much object-oriented programming as I was starting out, but it just became more simple when my programs reached over 1500 lines of code.

Yeah, I know.  I just don't get what makes it better to say, for example, 'g.say()' instead of 'say()'.  But yeah, I guess so.

Who builds classes just for a say()? Your example of classes is like this example of functions - "who needs funcprint(this) instead of cout  < this?

Yes, I know, I know.  I was just using that as an example, from a classic Ruby Hello World program (

class Greeter
def initialize( name )
@name = name.capitalize
end
def say
puts "Hello #{@name}!"
end
end
g = Greeter.new( "world" )
g.say

in case you were wondering).

Offline

 

#50 2011-10-02 16:07:35

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Various Areas of Python

So… right.

Offline

 

Board footer