Quantcast

Jump to content


Photo

Help with login code on Python!!!!!


  • Please log in to reply
30 replies to this topic

#1 nino

nino
  • 9 posts

Posted 30 April 2012 - 04:25 AM

Hi,
I'm new to using Python to login to websites and stuff.

I was hoping someone could give/help me with a piece of coding that will allow the user to input a custom username and password for the program to login to neopets using "http://www.neopets.c...gin/index.phtml".

Thanks :D

#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 April 2012 - 04:26 AM

http://www.neocodex....ost__p__1382824

That thread should give a decent starting point.

#3 nino

nino
  • 9 posts

Posted 30 April 2012 - 04:57 AM

Thank-You so much!

#4 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 05:20 AM

Hey, so, what made you choose Python? : P

#5 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 08:24 AM

Hey, so, what made you choose Python? : P


Oh god... watch out, he'll try and convert you to Ruby. :p

#6 Mishatu

Mishatu
  • 346 posts

Posted 30 April 2012 - 08:29 AM

Oh god... watch out, he'll try and convert you to Ruby. :p


But I thought Inky liked python?

#7 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 08:31 AM

But I thought Inky liked python?


I do like Python, but holy shit do I love Ruby...

#8 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 08:32 AM

I do like Python, but holy shit do I love Ruby...


Well, can you work out the airspeed velocity of an unladen swallow in Ruby?

#9 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 08:38 AM

Well, can you work out the airspeed velocity of an unladen swallow in Ruby?


Yes:

Net::HTTP.start('www.wolframalpha.com').get('/input/?i=speed+of+unladen+swallow').body

Syntax highlighter is shit. Needs language support. : /

Edited by Inkheart, 30 April 2012 - 08:39 AM.


#10 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 April 2012 - 08:41 AM

Yes:

Net::HTTP.start('www.wolframalpha.com').get('/input/?i=speed+of+unladen+swallow').body

Syntax highlighter is shit. Needs language support. : /


Wrong.

#11 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 08:42 AM

Wrong.


Go on...

#12 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 April 2012 - 08:43 AM

Go on...


You would need to find out if he meant a European or an African swallow first.

#13 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 08:44 AM

You would need to find out if he meant a European or an African swallow first.


*leaves thread*

#14 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 08:45 AM

Yes:

Net::HTTP.start('www.wolframalpha.com').get('/input/?i=speed+of+unladen+swallow').body

Syntax highlighter is shit. Needs language support. : /

Heretic bastard. ;)

Change 'dark side' to Ruby.

http://www.youtube.com/watch?v=siipB-1Zoac


*Edit: God, we didn't even manage 10 posts before we got off topic this time. :/

Edited by Russell, 30 April 2012 - 08:47 AM.


#15 Hydrogen

Hydrogen
  • Neocodex Co-Founder

  • 22213 posts


Users Awards

Posted 30 April 2012 - 09:02 AM

Going off topic is the natural progression of any conversation. At some point, it must go off topic. That is, if you believe the thread model to be a metaphor for conversations.

In any case, I find ruby to be horribly inconsistent. Certain "features" appear more to be after thoughts, hacked together and not very well designed. It's syntax doesn't really jive with me either, but I suppose that's more of a personal point. In either case, the set of philosophies that ruby is designed upon are somewhat opposite to the philosophies that python was designed upon. I think that is the main difference between the two languages. If you were to make a decision on which one to use, I would study those philosophies first. Knowing them really gives you a better understanding of why certain language constructs are the way they are.

#16 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 April 2012 - 09:07 AM

*Edit: God, we didn't even manage 10 posts before we got off topic this time. :/


It actually remained on-topic as they were related to a particular type of Python.

#17 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 09:11 AM

Going off topic is the natural progression of any conversation. At some point, it must go off topic. That is, if you believe the thread model to be a metaphor for conversations.


It actually remained on-topic as they were related to a particular type of Python.


God damn semantics.

Edit: In fact, seeing as we're here, I don't suppose any of you would know how to move a local variable from a function in a new-style class to the global scope?

Edited by Russell, 30 April 2012 - 09:13 AM.


#18 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 09:33 AM

In any case, I find ruby to be horribly inconsistent. Certain "features" appear more to be after thoughts, hacked together and not very well designed. It's syntax doesn't really jive with me either, but I suppose that's more of a personal point. In either case, the set of philosophies that ruby is designed upon are somewhat opposite to the philosophies that python was designed upon. I think that is the main difference between the two languages. If you were to make a decision on which one to use, I would study those philosophies first. Knowing them really gives you a better understanding of why certain language constructs are the way they are.


Oh? Please do be a bit more specific regarding the horrible inconsistencies. "Certain 'features'" is an extremely generic way to begin a critique. Syntax is almost always entirely personal, but they both have something going for them in different ways. Whitespace-significance is awesome, obviously, but paren-less methods could be considered just as aesthetically pleasing to the right eyes.

They were most definitely designed with polar opposite philosophies in mind, but I find TOOWTDI to be more burden than boon. Ruby is, to my knowledge, the only programming language that was explicitly designed with the intention of making the programmer happy rather than the compiler/interpreter, and it shows. So many things become instantly intuitive once you've familiarized yourself with the basics. The selling point of doing it one way is that other programmers will understand your code, but proper documentation alleviates that issue completely, and one should always document code intended to be consumed by other developers.

Ruby does give one an almost psychotic amount of freedom, but it's not like production code shoots fireworks just because it can. Open classes and being able to attach a closure to practically any method make the language stupid powerful, but of course it must be used wisely, and it's clearly the case that it usually is. I don't hate Python at all; it has a lot going for it, is slightly easier to teach and learn, and is clearly the ideal scripting language for doing any scientific calculation. But having to pass "self" everywhere, single-expression lambdas, and the constant catch-up that it seems to have play with Ruby (Sinatra before Flask, gem before pip) make it less than ideal in my book.

I don't suppose any of you would know how to move a local variable from a function in a new-style class to the global scope?


Either push it into the globals() dict or declare it with the global keyword before modifying it inside of the function.

Edited by Inkheart, 30 April 2012 - 09:35 AM.


#19 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 09:49 AM

Oh? Please do be a bit more specific regarding the horrible inconsistencies. "Certain 'features'" is an extremely generic way to begin a critique. Syntax is almost always entirely personal, but they both have something going for them in different ways. Whitespace-significance is awesome, obviously, but paren-less methods could be considered just as aesthetically pleasing to the right eyes.

They were most definitely designed with polar opposite philosophies in mind, but I find TOOWTDI to be more burden than boon. Ruby is, to my knowledge, the only programming language that was explicitly designed with the intention of making the programmer happy rather than the compiler/interpreter, and it shows. So many things become instantly intuitive once you've familiarized yourself with the basics. The selling point of doing it one way is that other programmers will understand your code, but proper documentation alleviates that issue completely, and one should always document code intended to be consumed by other developers.

Ruby does give one an almost psychotic amount of freedom, but it's not like production code shoots fireworks just because it can. Open classes and being able to attach a closure to practically any method make the language stupid powerful, but of course it must be used wisely, and it's clearly the case that it usually is. I don't hate Python at all; it has a lot going for it, is slightly easier to teach and learn, and is clearly the ideal scripting language for doing any scientific calculation. But having to pass "self" everywhere, single-expression lambdas, and the constant catch-up that it seems to have play with Ruby (Sinatra before Flask, gem before pip) make it less than ideal in my book.



Either push it into the globals() dict or declare it with the global keyword before modifying it inside of the function.


An example please? I'm absolutely shit with dictionaries. :(

#20 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 09:52 AM

An example please? I'm absolutely shit with dictionaries. :(


No.

#21 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 10:00 AM

No.


Well, in that case:

Spoiler


#22 Inkheart

Inkheart
  • 268 posts

Posted 30 April 2012 - 10:02 AM

Well, in that case:

Spoiler


I am so, so down, bro, but you gotta get your research face on. Still, because you asked nicely:

def foo():
  global localvar
  localvar = 10

foo()
print localvar

def bar():
  globals()['localvar2'] = 20

bar()
print localvar2

But really, dude, Google is a curious human being's (and, by extension, a programmer's) best friend. What sane person shuns their best friend?

#23 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 30 April 2012 - 10:09 AM

But really, dude, Google is a curious human being's (and, by extension, a programmer's) best friend. What sane person shuns their best friend?


What, you don't think I've tried?!
In my past couple of years on Earth, I've learned to be variably independent - most than what most people my age are inclined to do.
So, for future reference, (in essence) cut me some slack. :)
Cheers for the example nonetheless.

Edited by Russell, 30 April 2012 - 10:14 AM.


#24 Norava

Norava
  • Pro Can Cran

  • 547 posts


Users Awards

Posted 30 April 2012 - 06:30 PM

Well, can you work out the airspeed velocity of an unladen swallow in Ruby?


I'm sure you saw this on reddit today...Posted Image

#25 Hydrogen

Hydrogen
  • Neocodex Co-Founder

  • 22213 posts


Users Awards

Posted 30 April 2012 - 07:47 PM

I've broken up my response into bits so its easier to follow. Sorry this is a bit late but I can't formulate a worthwhile response while at work so things have to wait until I get home.

Before I begin, I just want to say that I don't think Ruby is a bad language. I just find it to be inconsistent and in disagreement with my own personal philosophies on programming language design.

Oh? Please do be a bit more specific regarding the horrible inconsistencies. "Certain 'features'" is an extremely generic way to begin a critique. Syntax is almost always entirely personal, but they both have something going for them in different ways. Whitespace-significance is awesome, obviously, but paren-less methods could be considered just as aesthetically pleasing to the right eyes.

You're right, syntax is a personal preference. In general, this is true, but syntax is also meant to force some structure onto the program such that it is readable to the programmer. Programs are more often read than they are written, so a readable syntax is a requirement. But what consists of a readable syntax is largely based on what a programmer is used to. Non-readable syntaxes can become readable syntaxes over time. Since you brought up parenthesis-less function calls, we'll discuss those. Take the following code, for example:

def foo(i)
    return i - 1
end

puts foo 10 * 2
If I were to read this, I wouldn't immediately know whether foo will receive 20 as the parameter or will it receive 10, and then multiply the result by 2. It's only by trying it out in the interpreter that I can find out for sure:

>> def foo(i)
>>     return i - 1
>> end
=> nil
>> foo 10 * 2
=> 19
Turns out that foo receives 20 as a parameter, and returns 20 - 1, 19 as the result. A construct like this could lead to programming errors that are really difficult to track down because the syntax doesn't help you any here. You could say that it's better to be explicit about things like this and put parenthesis around the ambiguous parts. But then why didn't we just stick to the tried and true convention of placing parenthesis around arguments?

It gets even more confusing when you have functions that don't take arguments and use them without parenthesis:
def foo
    return 1
end

puts foo + 1
a = foo
Is foo a local variable? A function? I don't know unless I really read the code well. It's clear in small amounts of code, but when your code is large and organized in multiple files and modules, if you start doing stuff like this, things can become very confusing, very quickly. I find the deviation from the mathematical function syntax and metaphor to be harmful.

They were most definitely designed with polar opposite philosophies in mind, but I find TOOWTDI to be more burden than boon. Ruby is, to my knowledge, the only programming language that was explicitly designed with the intention of making the programmer happy rather than the compiler/interpreter, and it shows. So many things become instantly intuitive once you've familiarized yourself with the basics. The selling point of doing it one way is that other programmers will understand your code, but proper documentation alleviates that issue completely, and one should always document code intended to be consumed by other developers.

What's the need to document your code when the language supports self-documenting code? I'm not saying this to say that Python supports this. What I'm saying is that Ruby takes a lot of influence from Perl and Perl is known to be notoriously non-self-documenting. I think this just goes down to philosophy again. I think it's better to have one way to do it and that's just a personal philosophy. It would be a mistake to say that Ruby was a bad language because it didn't sit well with my own personal philosophies. I just don't like Ruby because of it.

Ruby does give one an almost psychotic amount of freedom, but it's not like production code shoots fireworks just because it can. Open classes and being able to attach a closure to practically any method make the language stupid powerful, but of course it must be used wisely, and it's clearly the case that it usually is. I don't hate Python at all; it has a lot going for it, is slightly easier to teach and learn, and is clearly the ideal scripting language for doing any scientific calculation. But having to pass "self" everywhere, single-expression lambdas, and the constant catch-up that it seems to have play with Ruby (Sinatra before Flask, gem before pip) make it less than ideal in my book.

The catch-up you talk about is not really language features but tools that were built with the language. It would be unfair to compare those as language features. They don't really have a place in this discussion, sorry to say :/.

I don't disagree that Ruby gives you a lot of freedom. I just find it inconsistent:

Use a local variable before assignment and you get an ArgumentError. Use a global before assingment and you get nil. I can't tell you how many times I've been bitten by this. At this point, it's just really annoying.
>> puts foo
ArgumentError: wrong number of arguments (0 for 1)
	from (irb):15:in `foo'
	from (irb):15
>> puts $foo
nil
=> nil
Even weirder, assigning an undefined variable to itself before it is defined causes nil. Why doesn't that happen when you try to do the same thing with another undefined local variable?
>> a
NameError: undefined local variable or method `a' for main:Object
	from (irb):28
>> a = b
NameError: undefined local variable or method `b' for main:Object
	from (irb):29
>> a = a
=> nil
Convert to float using .to_f, you get a best effort. Convert to float using Float cast, you get an exception. Why aren't they in synchronous? Which one is the correct one to use? I'm not sure and I don't think anyone else is either.
>> "03.22".to_f
=> 3.22
>> "03.a22".to_f
=> 3.0
>> Float("03.22")
=> 3.22
>> Float("03.a22")
ArgumentError: invalid value for Float(): "03.a22"
	from (irb):24:in `Float'
	from (irb):24
Possibly the most annoying thing out of all of this that has recently bitten us at work is dealing with timeout exceptions. Consider the following code:
require 'timeout'

begin
    timeout 0.1 do
        sleep
    end
rescue
    puts "got here"
end
When you run this, you'll get
Timeout::Error: execution expired
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:60
	from (irb):40
It turns out, Timeout::Error is not a StandardError, so you have to remember to add a rescue for this specific case or your entire program comes crashing down. Apparently this inheritance problem has been fixed in ruby 1.9, but that's the exact kind of issue that I'm talking about. The design was bad to begin with. It's great that it's fixed now, though, but I wonder what the rationale behind doing it like this was. There are more like this:
StopIteration, SystemStackError, LocalJumpError, EOFError, IOError, RegexpError, FloatDomainError, ZeroDivisionError, ThreadError, SystemCallError, NoMemoryError, SecurityError, RuntimeError, NotImplementedError, LoadError, SyntaxError, ScriptError, NoMethodError, NameError, RangeError, IndexError, ArgumentError, TypeError, StandardError, Interrupt, SignalException, fatal, SystemExit
It's almost as if you need to have a general rescue and a SystemError rescue. Why? What's the point of the general rescue if it isn't general?

And then there is this. Here's a visualization of the grammar for ANSI C:
Posted Image

Python:
Posted Image

Ruby:
Posted Image

I think it's pretty clear from these visualizations that Ruby has a much more complicated syntax.

These are just some examples of things that I thought of off the top of my head. After having to work with Ruby at work for the past two years, I can honestly say that I'm not really impressed by the language. I find it inconsistent. I feel like it lays traps for me and waits in the shadows to catch its prey. I don't enjoy working with it. But your mileage may vary.

Hm, this post turned out to be way longer than I expected it to be. Sorry.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users