OK, this makes no sense....
This 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?
Offline
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
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
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)
Offline
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
fire219 wrote:
wulfmaster wrote:
don't you need to import the time plugin?
Yea, just found that out.
![]()
Python is easy for me. I like the modules though, they make is so organised!
Offline
wulfmaster wrote:
fire219 wrote:
wulfmaster wrote:
don't you need to import the time plugin?
Yea, just found that out.
![]()
Python is easy for me. I like the modules though, they make is so organised!
![]()
And look better than using namespaces in C++.
Offline
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).
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
Well then, anyone got an answer for the riddle? This Is The Hint.
Offline
Is there a way I can publish games online from python?[/stupid question]
Offline
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
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
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.
Offline
flamekyle wrote:
I should try Python, ...maybe
Um, okay. I personally like it. And besides, it's got Ogre3D available for it.
Offline
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
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
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
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