Skip to content

Instantly share code, notes, and snippets.

@divinity76
Last active June 13, 2022 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/ee7bcc0ae3f86b569f67382ee2360dc5 to your computer and use it in GitHub Desktop.
Save divinity76/ee7bcc0ae3f86b569f67382ee2360dc5 to your computer and use it in GitHub Desktop.
python complains

just started trying Python, and..

1: Python doesn't have constants. you can't do

class C {
  const FOO=123;
}

in Python. (however "constants" are conventionally ALL_UPPERCASE, and linters may complain if you're modifying an ALL_UPPERCASE)

2: Python doesn't support private members, everyting is always public, you can't do:

class C {
    private const FOO=123;
}

in Python. (however private members are conventionally prefixed with _ , eg _FOO=123 is the similar to a "private constant FOO")

3: argument and return types are completely ignored in Python: argument types

4: binary data seems to be a royal pain in Python.. want to write \xFF to stdout in python? try

import sys;
str = "\xFF";
sys.stdout.buffer.write(str.encode("raw_unicode_escape"));

yeah... compare that with php:

echo "\xFF";

5: you can't really pass strings by reference. want to port a function like

<?php
function f(string &$str): void {
    $str="foo";
}
$str="a";
f($str1);

to Python? it can't really do that, you have to dick around it somehow, like accepting a list with your string in index [0].. the equivalent Python function would be something like

def f(listWithStringInIndex0: list)->None:
    listWithStringInIndex0[0]="foo";

str="a";
hackyList=[str];
f(hackyList);
str=hackyList[0];

Unimpressive, Python..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment