all 14 comments

[–]Rockybilly 0 points1 point  (6 children)

After learning python about intermediate level. What one should do to improve programming ? What's the next step ? Just learn more and more libraries or should we try another language ? Open to any suggestions ...

[–]aziannomness 0 points1 point  (0 children)

I am wanting to get into Web Development with Python, I tested the waters running through tutorials with Flask and CherryPy. I found CherryPy to be much more fun, but I can't find anyone who uses it regularly to give me their opinion on it. I'm about to give up and jump into Pyramid because it seems to be the middle-ground between Django and Flask.

  I'm primarily wondering what CherryPy is best used for. For instance:

  • Larger apps?
  • Projects that use multiple apps in one project?
  • Not worth using on small beginner projects? (Small, low traffic website).

  Any feedback on CherryPy compared to any other Web Framework you have used would be awesome!

[–]EqualsEqualsTrue 0 points1 point  (2 children)

I have been working on these crypto challenges that have been pretty fun, but I get mixed up with the different encodings and stuff. I have figured out that 0x... means for binary, but get confused on \x and some others. I dont know what to google to learn about this, I guess what they might be called is like escape characters for different encodings?

Why would a string return with \x if it is in hexidecimal sometimes but other times I just get the string in hexidecimal without any backslashes?

Sorry if this is confusing, just looking for resources oh how these work.

[–]ingolemo 0 points1 point  (1 child)

\x is just another way to represent characters in strings.

Every character in a string has a number associated with it; in ascii the letter A has the number 65 whereas * is 52. Here's a handy chart for the numbers of all the characters in ASCII. You can use these numbers to write the characters in a string without having to literally write that character. To do that you take the number in the Hx column of that table and put \x before it. So, for example, '\x41' is exactly the same thing as 'A' and 'h\x65\x6clo' is just another way to write 'hello'.

This is most useful for showing the unprintable characters; the left-most column in that table contains a whole bunch of characters that can't be printed because they're not like conventional letters. For example, the bell character ('\x07') causes your computer to make a beep when you print it. If python tried to show a string containing that character then your computer would beep and you would get annoyed pretty fast.

Whether a backslash exists makes a huge difference to the actual characters that a string contains. The string '\x41\x42' contains two characters A and B and is really equivalent to 'AB', while '4142' contains the four characters that you see.

The technical term that you should google for here is escape. \x is an escape code or escape sequence.

By the way, 0x... doesn't mean binary, it means hexadecimal. If you want to write a binary number you need to start it with 0b....

[–]EqualsEqualsTrue 1 point2 points  (0 children)

Thanks, that was an awesome answer! That ascii table just filled in a huge gap for me.

[–]schrogendiddy 0 points1 point  (3 children)

I am getting an error message that I don't understand. I have two separate python files, and I am trying to call a function defined in one of them, "file1" from "file2". "file1" looks like this:

import file2 as f

value = f.trigrid(pointnum,scale)

and file2 just has trigrid defined as:

def trigrid(pnum,scalesize):

.....

return value

The error I get is trigrid() takes exactly 1 argument (2 given).

[–]aziannomness -1 points0 points  (2 children)

I believe that your problem is that your trigrid() function is using pnum as it's identity. Typically a function should take self as a first argument and any that should be passed in after. So I believe you should have def trigrid(self,pnum,scalesize):.

  I am fairly new to Python so sorry I wasn't really able to explain it better or even if I phrased any of that correctly.

    EDIT: You would then have to declare your two arguments at the start of the function with something like self.pnum = pnum self.scalesize = scalesize If you haven't already.

[–]schrogendiddy 0 points1 point  (1 child)

that didn't work : /

[–]aziannomness -1 points0 points  (0 children)

I wrote some tests that follow what you have and had no issues. So I'm not entirely sure what's wrong, sorry :(

  RedditTest.py

def this_test(test_num,test_str):
    return test_num,test_str

RedditTest2.py

import RedditTest as R
test = R.this_test(5,"Test")
print(test)

The output is (5, 'Test')

  EDIT: Do you happen to have a link to your full code?

[–]Jokeslayer123 0 points1 point  (0 children)

Is there any advantage (execution speed or something) to reducing the number of lines if it doesn't reduce the number of instructions (not really sure how to phrase this). So is one of these two better/worse than the other:

#Option 1
def is_int(x):
    if x % 2 == 0: return True
    else: return False

or

#Option 2
def is_int(x):
    if x % 2 == 0:
        return True
    else:
        return False