• bennr01

    BTW, PyPy (the python JIT which is in many usecases faster than CPython) will continue to support py2 indefinetly and probably forever. So as long as you do not have to use c-dependent modules and are OK with using outdated modules, it is a good way to continue using py2 after its EOL.

    posted in Pythonista read more
  • bennr01

    @mikael You are right. This was only meant as a suggestion for reducing the number of times you have to write my_property (for a complete getter/setter/deleter setup it would be 3 instead of 5 times). Your decorator @prop is indeed neat, but it may still be useful to remember the my_property = property(...) syntax in case you (or anyone else who reads this) may find themself in a situation where you can not use it (due to code style guidelines or other reasons). I had not seen that you actually used this syntax in your example above and thought it may be a nice tip for you.

    would I not still need to maintain 3 names – property, getter and setter?

    I am not sure, but you may be able to use lambda in this case, which could still be usefull for some cases like read-only properties. Also, in some cases the getter and setter may only be calling some other aliases (like getting/setting text labels).

    posted in Pythonista read more
  • bennr01

    I am not sure, but IIRC, you could also use my_property = property(getter, setter) instead of the @property syntax.

    posted in Pythonista read more
  • bennr01

    Hi guys, is anyone interested in beta testing a few new features for StaSh?
    I have spend the last few weeks to port StaSh to PC, but the changes were rather extensive so i may have broken a few things.
    If you are interested in helping, here is a list of stuff which needs to be tested:

    What needs to be tested:

    • [iOS] Check that everything previously working still works (installation, updates, commands, ...)
    • [PC] Check that the port does not contain any bugs.
    • [iOS/PC] Check that StaSh still runs on both py2 and py3. I only had the chances to test the changes on py2.

    What is not working on PC:

    • The telnet and ssh commands will not work on PC. They need ui.measure_string which i am not sure how to implement using tkinter.
    • easy_config uses its own UI, which was not ported.

    How to install:

    • PC: Clone/download the crossplatform branch of bennr01/stash from github and run python setup.py install. Start with the launch_stash.py command.
    • iOS: If you do not already have StaSh installed, install the normal release first, then force quit pythonista. Afterwards, run selfupdate bennr01:crossplatform and force quit pythonista again.

    How to report bugs:
    If you find any bugs, please report them either in this thread or in my StaSh fork. Please do not report them directly to the main repo to reduce the number of issues created there.
    Of course, pull requests are welcome :)

    posted in Pythonista read more
  • bennr01

    A few month ago someone asked a similiar question on reddit.
    Assuming you can run python on both sides, you can use this example. For more details, please see the discussion in the reddit discussion linked above. This example does not use SSH, but the socket & webbrowser modules instead.

    posted in Pythonista read more
  • bennr01

    @danaportenier replace def __ini__(...) with def __init__(...) (notice the t)

    Edit: You can also replace your if-construct with something like this:

    inp = input("What was the month (1-12) ").strip()
    self.month_input = {
       "01": 1,
       "1": 1,
       "Jan": 1,
        "02": 2,
        "2": 2,
        "Feb": 2,
        }.get(inp, None)

    This does the following:

    1. ask the user for input, saving it in the local variable inp
    2. create a dictionary (key-value mapping) containing the inputs and their numeric values, then checks if inp is in the dictionary. If it is, the value for the input is assigned to self.month_input, otherwise the value None is used.

    I would also recomment to restructure the code as follows:

    class UserInputDate(object):   # inherit from object, use PEP8-style naming conventions
        MONTH_TO_YEAR = {...}  # your month names to values, as dicussed above
        def __init__(self, month, year):
            self.month = self.MONTH_TO_YEAR.get(month, None)   # do not call I/O functions from `__init__`. You may later need the same class without input.
            self.year = year
        def from_input(cls):
            # use a classmethod to directly create the class from input
            month = input("Please enther month (1-12)")
            year = input("Please enther year")
            return cls(month, year)
        def combine(self):
             # as your old code, but using self.month and self.year
    if __name__ == "__main__":
        # place top-level code inside such an if-statement, so it does not get executed on import
        primary_bariatric_date = UserInputDate()

    The above code is not tested, but it should prove you with some tips regarding class layout.
    Most of these changes seem useless at first, but are more useful later on.

    posted in Pythonista read more
  • bennr01

    It is a new StaSh bug. I do not know the exact details, but it seems like StaSh only creates an empty file for the command. This may be caused by a recent change. Could you please provide the output of the version command?

    posted in Pythonista read more
  • bennr01

    @ccc I also oppose dropping python 2 from pythoniststa 3 for several reasons.

    1. I still have a huge amount of py2 code which i do not want to port
    2. I do not want to be forced to adapt py3. While i am slowly, but steadily switching over to py2 and py3 compatible source and later to only py3, i want to do this on my own pace and not suddenly because one of my most used apps dropped support for py2.
    3. Pythonista 3 is advertised on the appstore as being both py2 and py3 compatible. Some people, including me, probably would not have bought pythonista3 if it did not support py2. Before @omz announced that pythonista3 would support both versions, I had not even considered buying pythonista3. Chances are, that a few people may be outraged if py2 was dropped. You may argue that they do not have to update, but maybe some people have automatic updates on and will know py2 was dropped before it is too late. And i do not want to see that shitstorm.
    4. Why should we even drop py2? Just because it is officialy EOL does not mean we have to drop support for py2. While it would be nice if we would have a faster start-up time, a simple do not load py2/py3 switch would also do the job.
    5. I sometimes work on py2 code on my iPhone and like it.
    6. Py3 is an abomination which i will fight until my very last breath.

    Well, in the end it is the decision of @omz .

    posted in Pythonista read more
  • bennr01

    @sendog3c could you please provide a bit more information about your problem?

    But I have problem with parameter, data gotten from sender (str, int).

    What exactly do you mean? sender.title should always be a str. If you want to convert a str to an int, use int(text_here). If you want to convert a int to a str, use str(int_here).

    def button_tapped(sender):
        #if  button_tapped == b_top1.title('SUM'):
        #itexto1 = 'Hello World'
        texto1 = sender.title
        #texto1 = str(300)  
        return texto1

    You can not return something from a callback. Instead, do the operation directly in the callback.
    An example:

    def button_tapped(sender):
        a = ...  # value for a here
        b = ...  # value for b here
        action = sender.title
        if action == "SUM":
            result = a + b
        # .. other operations
        txt_field1.text = str(result)

    Also, the following will not work:

    txt_field1.text = button_tapped()

    If i understand correclty, you want to change the text when a button was pressed. However, button_tapped() will be evaluated right in this line, before the UI is presented. Instead, modify the text in the callback as shown above.

    posted in Pythonista read more
  • bennr01

    @Robert-Buckley said:

    because once those controls have been used, they disappear and don't come back.

    Uhmm... what? This is not supposed to happen...

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!