PythoFF

Menu

Sign in:

read us on

home/2018/10/29/1ca97a1a591c6348da6c5d6a09fb79b1564d0ce8.jpg

Python Community Interview With Michael Kennedy

Michael Kennedy is the host of the most popular Python podcast, Talk Python to Me, as well as a co-host on the Python Bytes podcast. Find out why he got started with Python, how he manages to produce so much Python content, and what he thinks about while he's in traffic!

PyDev of the Week: Anthony Sottile

This week we welcome Anthony Sottile (@codewithanthony) as our PyDev of the Week! Anthony is one of the maintainers for the tox and pytest packages. He is also on the “deadsnakes” PPA team, which backports Python for certain EOL Linux distros. While you can discover a little about Anthony on his website, you will probably learn more from his Github profile. Can you tell us a little about yourself (hobbies, education, etc): From a young age, I was always fascinated with computers. Some of my earliest programs were written to simplify (read: _cheat_) on homework. A word document containing a rudimentary quadratic-formula-solving gui interface using visual basic was copied to quite a few floppy disks. I eventually switched to web development as it was a much more accessible distribution mechanism. I attended the University of Michigan (go blue!) originally studying biochemistry. I wanted to change the world through medicine and research but two years into the program I decided to switch to my stronger passion. And after an intense scramble to squeeze a four year program into two years I graduated with a computer science degree! Most of my personal time is spent biking (which I meticulously track in a fancy spreadsheet — 4600 miles logged this year). Some of my other passions are hiking, cooking, running, ski racing, playing violin, and writing a bit of poetry (is this a dating site?). And of course I spend a significant portion of time building and contributing to open source software 🙂 My crowning achievement is becoming a Pokémon master — not only completing a living Pokédex but enduring _extreme_ tedium by capturing every single possible shiny Pokémon legitimately. It’s all been downhill since then 🤣. Continue reading PyDev of the Week: Anthony Sottile →

Звёздный Python: где и как используются * и **

В Python много где можно встретить * и **. Два этих оператора порой могут быть загадкой как для начинающих программистов, так и для тех, кто пришёл в Python из других языков, не имеющих точно таких же операторов. Сегодня мы поговорим о том, как их можно использовать.

home/2018/10/27/a5353b8c1d99fe8b5d2013024ac63ca3ac89d460.jpg

Python для ребёнка: выбор самоучителя

Мой сын заинтересовался программированием на Python, и у меня появился вопрос – есть ли сегодня возможность купить книгу для ребёнка в качестве самоучителя? Самоучители для взрослых детям не подходят – мотивации продираться самостоятельно через учебники программирования и у взрослых не всегда хватает, а у ребёнка скучное «академическое» изложение вообще может убить весь интерес к предмету на пятой странице. К счастью, на момент написания статьи (конец 2018 года) выбор оказался весьма широк – есть как переводные, так и отечественные книги, нацеленные на детскую и подростковую аудиторию. В ходе поиска, отсеяв книги по Python 2, я смог найти 10 свежих книг по Python 3 для детей, изучил каждую их них вживую в офлайн-магазинах, и результатами своих изысканий хочу поделиться с вами в статье под катом.

home/2018/10/27/7fff2cfdc5d7ab5e4a94c7fb1c79c891ae14e0db.jpg

Python: как уменьшить расход памяти вдвое, добавив всего одну строчку кода?

Привет habr. В одном проекте, где необходимо было хранить и обрабатывать довольно большой динамический список, тестировщики стали жаловаться на нехватку памяти. Простой способ, как «малой кровью» исправить проблему, добавив лишь одну строку кода, описан ниже. Результат на картинке: Как это работает, продолжение под катом.

Авторизация пользователей в Django через GSSAPI и делегация прав пользователя серверу

Недавно нам с коллегами понадобилось реализовать прозрачную (SSO) авторизацию в нашем проекте. Сейчас довольно мало информации по теме особенно на русском языке. По этой причине решено было поделиться с потомками реализацией подобного функционала. Итак задача заключалась в следующем: необходимо было настроить прозрачную авторизацию через GSSAPI от пользователя на сервер, а так же иметь потом возможность от имени этого пользователя ходить в БД.

home/2018/10/25/8cc539b708467c87a95f7459ac0891ce22cb2953.jpg

Python 101: Episode #30 – The configobj Package

In this episode you will learn how to use the configobj package. This is a 3rd party package that I think is better and easier to use than Python’s built-in configparser module. You can also read the chapter this video is based on here or get the book on Leanpub Related Reading A Brief ConfigObj Tutorial ConfigObj + wxPython = Geek Happiness

home/2018/10/24/f9a97d872101f13ffadad0fb67998b63091ce798.jpg

Practical Text Classification With Python and Keras

Learn about Python text classification with Keras. Work your way from a bag-of-words model with logistic regression to more advanced methods leading to convolutional neural networks. See why word embeddings are useful and how you can use pretrained word embeddings. Use hyperparameter optimization to squeeze more performance out of your model.

Working with Jupyter Notebook Widgets

What are Jupyter widgets? A widget is an “eventful python object” that in the case of Jupyter Notebook, resides in the browser and is a user interface element, such as a slider or textbox. Jupyter supports a fairly wide array of widgets including the following: Numeric Boolean Selection String Image Button Output Animation Date picker Color picker Controller (i.e. game controller) Layout We won’t cover every type of widget in this article, but we will get to see a fairly wide range of them in action. For a full list you can check out the documentation. Or you can run the following code in your Notebook: import ipywidgets as widgets   print(dir(widgets)) If you have ever created a user interface in the past, then you probably already understand what a widget is. If you haven’t, then let’s just take a second to define what they are for. A widget is used to create an interactive graphical user interface for your user. The widgets synchronize stateful and stateless information between Python and Javascript. We looked briefly at how to create widgets using the interact and interactive functions in the previous article. In this tutorial we will create the widgets directly and learn more about how they work. Creating a Widget A widget can be created really easily. Let’s create a simple slider for demonstration purposes. Create a new Jupyter Notebook and put the following code into a cell: import ipywidgets as widgets   widgets.IntSlider() When you run the cell, you should see something like this: As you can see, the default value is zero for the slider. If you want to save the widget to a variable, then you will need to tell Jupyter to show the widget using the display function: import ipywidgets as widgets from IPython.display import display   btn = widgets.Button(description='Press Me') display(btn) Here we add the extra import that we need to display a widget and we create a simple Button. Note that we had to specify its description so that the button would have a label. Finally we called the display function and passed it the widget object. The result looks like this: Now let’s back up a second and create that slider again, but this time around we will use display to show it twice: import ipywidgets as widgets from IPython.display import display   btn = widgets.IntSlider() display(btn) display(btn) If you put the code above into a cell in your Notebook and run it, you should see two sliders: Try moving around one of the sliders. You will quickly discover that when you move one slider, the other slider also moves. The reason that this happens is that we only create ONE slider object. The actual visible widgets are both pointing to the same object underneath, so when you move one you are effectively moving the other. You can think of these two sliders are two views to the same object. Of course, if you had created two IntSliders and assigned them to unique variable names, then you could move them independently of each other. Closing a Widget You can close a widget by calling its close() method. If you want to remove the widget, just clear the cell. Properties and Keys of a Widget Jupyter widgets follow a set of rules for their properties. If you want to get a full listing of widgets properties and methods, you can use Python’s dir() function to introspect the widget for you: dir(btn) Let’s say you put the code above in a new cell just below the cell that contains the code for your `IntSlider` widget. If you ran this new cell, you would get output like this: Try adjusting the slider to something above zero. Then create a new cell and enter the following code: btn.value When you run this, it will print out the current value of the slider. Widgets also have keys, which are such things as `description`, `min`, and `max` and `disabled`. For the full list of a widget’s keys, you can consult the documentation for the widget, read the source or just run this: btn.keys Also worth mentioning is that you can also set a property to a new value. So if you wanted to set the slider to a new value and add a description, you could do the following: btn.value = 50 btn.description = 'Hello slider' If you run this code, you will see the slider update its value and description. Widgets also support setting properties when you instantiate the widget. For example, if we wanted to, we could set a few of our Slider’s properties when we create it: import ipywidgets as widgets from IPython.display import display   btn = widgets.IntSlider(value=10, description='My Slider', orientation='vertical') display(btn) When you run this code, you will see that the widget looks a bit different: Linking Two Widgets Some Jupyter widgets can be linked together. For example, you can link a FloatText widget to a FloatSlider widget. What this means is that when one widget is updated, the other will be too. This is known as “synchronization of attributes”. Let’s take a look at a simple example: text = widgets.FloatText() slider = widgets.FloatSlider() display(text,slider)   mylink = widgets.jslink((text, 'value'), (slider, 'value')) Here we create two widgets and display them both. Then we call widgets.jslink and tell it to link the value of the text and slider together. When you use the jslink method, you are linking the widgets from the client side. This makes the widgets sync up more robustly because they will be using the local machine’s hardware. You can also use jsdlink, which will create a unidirectional link between two widgets on the client side. What that means is that you can make one of the two widgets affect the second widget whereas the second widget will NOT affect the first. Try changing the example above to use jsdlink like we do below: text = widgets.FloatText() slider = widgets.FloatSlider() display(text,slider)   mylink = widgets.jsdlink((text, 'value'), (slider, 'value')) Now try editing each widget’s value and see how they interact. It’s hard to demonstrate in the book but basically when you change the text widget it will change the slider to match. However if you change the slider’s value, the text control won’t change. There are also two other methods you can use to link two widgets together: link dlink These methods work in the same way as jslink and jsdlink respectively, except that they will talk to the server so you might experience some latency when using them. Frankly on your local machine, you probably won’t see much difference between the two. Finally I want to point out that you can also unlink the widgets by calling the link’s unlink method: mylink.unlink() You can try this out by adding this code to the end of the cell where you created the linked widgets. If you do add it and re-run the cell, then you will find that the two widgets are no longer linked together. Events Linking widgets is closely related to widget events. An event occurs when you interact with a widget. For example, when you push a button, that is known as a click event. Let’s look at an example of how this might work using a button widget. import ipywidgets as widgets from IPython.display import display   btn = widgets.Button(description='Test') display(btn)     def my_event_handler(btn_object): print('You pressed the {} button!'.format(btn_object.description))   btn.on_click(my_event_handler) Here we import the various bits and pieces we need to use widgets and display them. Then we create a simple button and a function that is named my_event_handler. This is the event handler which is what you would bind your widget’s event to. To actually bind your button’s click event to this handler, you must call on_click and pass it the function that you want it bound to. You will note that the event handler accepts an argument implicitly, which is the button object itself. This allows you to access the button’s properties, so in this case I went ahead and told it to print out the label of the button. The following is a screenshot of what my code and button looked like when I ran it after pressing the button: What this also allows you to do is to bind multiple buttons to the same event handler. Here’s how you might do that: import ipywidgets as widgets from IPython.display import display   btn = widgets.Button(description='Test') other_btn = widgets.Button(description='Other') display(btn) display(other_btn)   def my_event_handler(btn_object): print('You pressed {}'.format(btn_object.description))   btn.on_click(my_event_handler) other_btn.on_click(my_event_handler) In this code, we create a second button called other_btn with a different label and bind it to the same event handler as the other button. Now you can try pressing the each button a few times and see how they behave. Here’s an example session: You can do this type of event binding with other types of widget events. You will need to look at the documentation for the widget or the source of the widget to figure out what events it supports. Speaking of the documentation, it also mentions something that Jupyter calls Traitlet events. These are IPython traitlets which basically give you a different method of binding an event to a function using the observe method. To get an idea of how you might use a traitlet, let’s run the following code in our Jupyter Notebook: print(btn.observe.__doc__) When I ran this code, I got the following output: Setup a handler to be called when a trait changes.   This is used to setup dynamic notifications of trait changes.   Parameters ---------- handler : callable A callable that is called when a trait changes. Its signature should be ``handler(change)``, where ``change`` is a dictionary. The change dictionary at least holds a 'type' key. * ``type``: the type of notification. Other keys may be passed depending on the value of 'type'. In the case where type is 'change', we also have the following keys: * ``owner`` : the HasTraits instance * ``old`` : the old value of the modified trait attribute * ``new`` : the new value of the modified trait attribute * ``name`` : the name of the modified trait attribute. names : list, str, All If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name. type : str, All (default: 'change') The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler. So how does this work? Basically you call observe with the name of the function that you want to bind to as well as which traits you want to “observe”. You can pass in a list of strings, set it to “All” or pass in a singular string. The documentation has a good example, but I am going to take it and expand it slightly to become the following: int_range = widgets.IntSlider() display(int_range)   def on_value_change(change): print(change) print(change['new'])   int_range.observe(on_value_change, names='value') The difference between this and the one you will find in the documentation is that I am printing out the change object too. This will tell us what we are dealing with. In this case, the output when you change the slider looks like this: {'owner': IntSlider(value=2), 'new': 2, 'old': 0, 'name': 'value', 'type': 'change'} 2 That tells us that the change argument is a dictionary of values and that the key new will give us the new value of the slider. So when we tell Jupyter to observe the value string, it will send in a dictionary of values. Interestingly this dictionary also contains the old value of the slider in addition to the new value. This can be useful to know in other widgets if you need to implement something like undo / redo, for example. Layout Jupyter widgets also have a layout attribute that they expose which allows you to set a number of CSS properties that you may use to control how widgets are laid out. These properties include size, display, box model, positioning and more. You can use the layout feature to make your widgets change sizes based on the available space. Let’s look at a simple example: from ipywidgets import Button, Layout from IPython.display import display   layout = Layout(width='50%', height='100px')   btn = Button(description='(50% width, 100px height) button', layout=layout) display(btn) Here we import our Button and a Layout. We set up the Layout such that it will make the widget take up 50% of the available width and 100 pixels high. Then we set the button’s layout argument to the layout that we just created. This is what the result looks like: You can apply layouts by creating a layout instance like we did in the previous example or you can have a widget use another widget’s layout directly. To demonstrate, let’s add the following code to the bottom of the cell that we just created in the previous example: btn2 = Button(description='Another button', layout=btn.layout) display(btn2) Here we set this new button’s layout to btn.layout, which basically makes our new button use the same layout object that the original button is using. You should end up seeing the button’s like this: Styling Interestingly, some widgets allow you to put in a description that is too long to be shown. from ipywidgets import IntSlider   IntSlider(description='A really long description') When you run this code, you will find that Jupyter cuts off some of the text: You can get around this issue by applying a style. The style to use in this case would look like this: style = {'description_width': 'initial'} Oddly enough, the documentation on Jupyter styles is pretty much non-existent. Looking at the source code in widget_int.py, it appears that the value, initial, refers to the initial label width. So when you create a style that has description_width as the key and set it to initial, you are, in effect, telling Jupyter to use the widget label’s string length as its width. To apply the style, you can just do the following: from ipywidgets import IntSlider   style = {'description_width': 'initial'} IntSlider(description='A really long description', style=style) And now your widget will look like this: Of course, the problem with this solution is that now your slider looks too small. We can solve that issue by using a helper function! Arranging Widgets There are some helper functions like HBox and VBox that you can use for combining widget and laying them out visually. The HBox will add widgets to it one at a time horizontally. You can think of it as lining up individual pieces in a horizontal line from left-to-right. Let’s use an HBox and a Label widget to solve our problem: from ipywidgets import HBox, Label, IntSlider   label = Label('A really long description') my_slider = IntSlider()   HBox([label, my_slider]) Here we import the pieces we need, create a couple of widgets and then add them to our HBox. The result is as follows: As you might expect, you can use a combination of HBox and VBox layouts to make complex layouts of your widgets. For example, you could add a couple of widgets to one HBox and a couple more to a second HBox and then add both HBoxes to a VBox to create a grid. Let’s go ahead and do that so you can see how that might work. from ipywidgets import Button, HBox, VBox   btn_one = Button(description='One') btn_two = Button(description='Two') btn_three = Button(description='Three') btn_four = Button(description='Four')   first_line = HBox([btn_one, btn_two]) second_line = HBox([btn_three, btn_four])   VBox([first_line, second_line]) Here we create four buttons and two HBoxes. The HBoxes each hold two buttons apiece. Finally we add the HBoxes to the VBox and this is what we end up with: in the documentation, so I will leave that one for you to read as an exercise. I also want to mention that there is one other widget for creating layouts called the GridBox. In my experience using wxPython, a cross-platform desktop user interface toolkit, I have found that using VBox and HBox type containers is more than enough for creating complex layouts of my widgets and the more advanced layout tools tend to make things more difficult unless you are already planning to do a grid-like interface. You are more than welcome to give these other types of layouts a try as they definitely have their place. Wrapping Up In this chapter we learned a lot about how to create and use Jupyter Widgets. We also learned how we can display, style and arrange them. There are lots of other things you can learn about widgets on by checking out the documentation on the topic or reading a few tutorials on the web. For example, Jupyter supports the ability for you to create your own custom widgets. It also supports the use of asynchronous widgets. I highly recommend using widgets in your Notebooks to give them some pizazz and to make them more useful too!

Creating Jupyter Notebook Widgets with interact

The Jupyter Notebook has a feature known as widgets. If you have ever created a desktop user interface, you may already know and understand the concept of widgets. They are basically the controls that make up the user interface. In your Jupyter Notebook you can create sliders, buttons, text boxes and much more. We will learn the basics of creating widgets in this chapter. If you would like to see some pre-made widgets, you can go to the following URL: http://jupyter.org/widgets These widgets are Notebook extensions that can be installed in the same way that we learned about in my Jupyter extensions article. They are really interesting and well worth your time if you’d like to study how more complex widgets work by looking at their source code. Continue reading Creating Jupyter Notebook Widgets with interact →

home/2018/10/23/59c3094ec4c7ae59f7cee50f3f5fde5d99ff00f1.jpg

Программатор для нового семейства tinyAVR на базе дешевого китайского конвертера CH340

Unified Program and Debug Interface (UPDI) — это однопроводной интерфейс для программирования/отладки новых 8-битных микроконтроллеров Atmel, пришедший на смену двухпроводному интерфейсу PDI, использовавшемуся для программирования микроконтроллеров AVR XMEGA.

home/2018/10/22/55f35fcdd9cb3ebe40263593af85a08f856267d6.jpg

Fresh Tutorials on Full Stack Python

There are a bunch of new tutorials on Full Stack Python that were written since the last time I sent out an email newsletter. These range from getting started with some popular open source projects to integrating third party APIs to... (read more)

home/2018/10/22/cadae3d6af8c8adf0afd32cb429420c16c4e96c0.jpg

Getting Started With Testing in Python

In this tutorial, you’ll learn how to create a basic Python unit test, execute it, and find the bugs before your users do! You’ll learn about the tools available to write and execute tests, check your application’s performance, and even look for security issues.

PyDev of the Week: Philip Guo

This week we welcome Philip Guo (@pgbovine) as our PyDev of the Week! Philip is the creator of the popular Python Tutor website and a professor at UC San Diego in the cognitive science and computer science department. Let’s take some time to get to know Philip! Can you tell us a little about yourself (hobbies, education, etc): I am an assistant professor of cognitive science and computer science at UC San Diego. My research and teaching revolve around the topic of how to greatly expand the population of people around the world who can learn programming skills. There’s a lot of great people working on training the next generation of software developers, but I’m also interested in how we can apply programming to many other fields including the physical sciences, social sciences, design, arts, and humanities. Outside of my normal work, I used to write a lot of articles on my website but lately I’ve been trying to stay off the computer in my off-time, so I’ve turned to recording vlogs, podcasts, and other audio/video content that don’t require me to be glued to the computer. Continue reading PyDev of the Week: Philip Guo →

wxPython: How to Open a Second Window / Frame

I see questions relating to the title of this article a lot. How do I open a second frame / window? How do I get all the frames to close when I close the main application? When you are first learning wxPython, these kinds of questions can be kind of hard to find answers for as you aren’t familiar enough with the framework or the terminology to know how to search for the answers. Hopefully this article will help. We will learn how to open multiple frames and how to make them all close too. Let’s get started! Opening Multiple Frames Creating multiple frames is actually pretty simple. You just need to create a subclass of wx.Frame for each new frame that you want to create. Or if the new frames can look the same, then you just need to instantiate the second class multiple times. You will also need a subclass of wx.Frame for the main application’s frame. Let’s write some code as I think that will make things clearer: import wx     class OtherFrame(wx.Frame): """ Class used for creating frames other than the main one """   def __init__(self, title, parent=None): wx.Frame.__init__(self, parent=parent, title=title) self.Show()     class MyPanel(wx.Panel):   def __init__(self, parent): wx.Panel.__init__(self, parent)   btn = wx.Button(self, label='Create New Frame') btn.Bind(wx.EVT_BUTTON, self.on_new_frame) self.frame_number = 1   def on_new_frame(self, event): title = 'SubFrame {}'.format(self.frame_number) frame = OtherFrame(title=title) self.frame_number += 1     class MainFrame(wx.Frame):   def __init__(self): wx.Frame.__init__(self, None, title='Main Frame', size=(800, 600)) panel = MyPanel(self) self.Show()     if __name__ == '__main__': app = wx.App(False) frame = MainFrame() app.MainLoop() So here we create two classes that subclass wx.Frame: OtherFrame and MainFrame. OtherFrame is what we will use for our extra frames while MainFrame is our main application’s window. We also create a subclass of wx.Panel to hold a button and a button event handler. The button will be used to create the extra frames. Try running this code and you will find that it can create any number of extra frames just by clicking the button multiple times. However if you try to close the main application with one or more of the other frames still running, then you will discover that the application will continue to run. Let’s learn how we can modify this code to close all frames when the main frame is closed. Closing All Frames You may have noticed this already, but both the MainFrame class and the OtherFrame class have parents set. The MainFrame class is hard-coded rather subtlety to None while OtherFrame has its parent just defaulted to None. This is actually the key to our issue. When you set a wx.Frame’s parent to None, it becomes its own entity with no dependencies. So it doesn’t care if another frame closes or not. However if we were to set all of the OtherFrame instance’s parent to be the MainFrame instance, then they would all close when we close the main frame. To make this change, all we need to do is change the on_new_frame function to the following: def on_new_frame(self, event): title = 'SubFrame {}'.format(self.frame_number) frame = OtherFrame(title=title, parent=wx.GetTopLevelParent(self)) self.frame_number += 1 Here we set the parent to the MainFrame by using wxPython’s wx.GetTopLevelParent function. Another way you could do this is to modify MyPanel’s __init__ to save off a reference to the parent parameter: def __init__(self, parent): wx.Panel.__init__(self, parent)   btn = wx.Button(self, label='Create New Frame') btn.Bind(wx.EVT_BUTTON, self.on_new_frame) self.frame_number = 1 self.parent = parent   def on_new_frame(self, event): title = 'SubFrame {}'.format(self.frame_number) frame = OtherFrame(title=title, parent=self.parent) self.frame_number += 1 In this case we just use the instance attribute here for setting our parent. Just to be thorough though, I want to mention one other way we could set the parent to the MainFrame instance and that is by calling GetParent(): def on_new_frame(self, event): title = 'SubFrame {}'.format(self.frame_number) frame = OtherFrame(title=title, parent=self.GetParent()) self.frame_number += 1 Here we just call the MyPanel’s GetParent() method to get the panel’s parent. This works because MyPanel is only used by the MainFrame. Things would get messy if we happened to use that panel class with other frames though, so I personally prefer the GetTopLevelParent method because it pretty much guarantees that we will get the right widget. Wrapping Up Working with multiple frames shouldn’t be hard. I hope this tutorial has shown you just how easy it is to do. You can use the concepts in this article to also create dialogs as they work in much the same way as frames do, although they tend to be modal. Thanks for reading and happy coding!

Работа с изображениями на Python

Тема сегодняшнего разговора — чему же научился Python за все годы своего существования в работе с изображениями. И действительно, кроме старичков родом из 1990 года ImageMagick и GraphicsMagick, есть современные эффективные библиотеки. Например, Pillow и более производительная Pillow-SIMD. Их активный разработчик Александр Карпинский (homm) на MoscowPython сравнил разные библиотеки для работы с изображениями на Python, представил бенчмарки и рассказал о неочевидных особенностях, которых всегда хватает. В этой статье расшифровка доклада, который поможет вам выбрать библиотеку под свое приложение, и сделать так, чтобы она работало максимально эффективно. О спикере: Александр Карпинский работает в компании Uploadcare и занимается сервисом быстрой модификации изображений на лету. Участвует в разработке Pillow — популярной библиотеки для работы с изображениями на Python, развивает собственный форк этой библиотеки — Pillow-SIMD, который использует современные инструкции процессоров для наибольшей производительности.

home/2018/10/18/8cc539b708467c87a95f7459ac0891ce22cb2953.jpg

Python 101: Episode #29 – Installing Packages

In this screencast we will learn how to install 3rd party modules and packages using easy_install, pip and from source. You can also read the chapter this video is based on here or get the book on Leanpub

home/2018/10/17/658fe994feb2b8ea7e2ab88ec8878e36d613b31b.jpg

Python, Boto3, and AWS S3: Demystified

Get started working with Python, Boto3, and AWS S3. Learn how to create objects, upload them to S3, download their contents, and change their attributes directly from your script, all while avoiding common pitfalls.

Jupyter Notebook Debugging

Debugging is an important concept. The concept of debugging is trying to figure out what is wrong with your code or just trying to understand the code. There are many times where I will come to unfamiliar code and I will need to step through it in a debugger to grasp how it works. Most Python IDEs have good debuggers built into them. I personally like Wing IDE for instance. Others like PyCharm or PyDev. But what if you want to debug the code in your Jupyter Notebook? How does that work? In this chapter we will look at a couple of different methods of debugging a Notebook. The first one is by using Python’s own pdb module. Continue reading Jupyter Notebook Debugging →

Интеграция с SAP ERP, на примере с Django-python, по протоколу oData(rest)

Добрый день, Хабр! Всегда была интересна тема интеграции больших систем вроде SAP с небольшими, но более гибкими, так-сказать взять лучшее из того и другого. В частности, в моем примере будет описана интеграция SAP ERP с Django. Задача: Из за введенного нашим любимым государством множества разных систем контроля: Егаис, Меркурий и многое другое, многие компании принялись адаптировать свои тяжелые, и мягко сказать неповоротливые системы (касается больших компаний) к новым условиям. Не буду говорить в каких в частности адаптировал и я, но в голове всегда крутилась мысль – Создать единую систему отслеживания всего на базе отдельной платформы. Средства: Не особо долго выбирав какие инструменты взять, я выбрал: Язык программирования Python – ввиду обилия библиотек со всем и вся, платформу Django, вот не спрашивайте почему Django, а не Flask или Odoo. Odoo я уже брал за платформу и хотелось изучить одну из этих, взял первую, ну не знаю почему, наверное из за большей простоты. ERP систему для разработки SAP- ну тут у меня не особо был выбор, т.к. я работаю в компании интеграторе SAP, поэтому у меня есть и знания и доступ к песочницам этой системы, что бы имея все условия спокойно делать свое дело беспрепятственно.

Testing Jupyter Notebooks

The more you do programming, the more you will here about how you should test your code. You will hear about things like Extreme Programming and Test Driven Development (TDD). These are great ways to create quality code. But how does testing fit in with Jupyter? Frankly, it really doesn’t. If you want to test your code properly, you should write your code outside of Jupyter and import it into cells if you need to. This allows you to use Python’s unittest module or py.test to write tests for your code separately from Jupyter. This will also let you add on test runners like nose or put your code into a Continuous Integration setup using something like Travis CI or Jenkins. However all is now lost. You can do some testing of your Jupyter Notebooks even though you won’t have the full flexibility that you would get from keeping your code separate. We will look at some ideas that you can use to do some basic testing with Jupyter. Continue reading Testing Jupyter Notebooks →

home/2018/10/15/e738d8ec62864d7d83551d4c5bf27b950fec32c2.jpg

Python's range() Function (Guide)

Get a solid understanding of how to use Python's built-in "range" function, how its implementation differs in Python 3 vs 2, and how you can work around some of its limitations.

PyDev of the Week: Marc Garcia

This week we welcome Marc Garcia (@datapythonista) as our PyDev of the Week! Marc is a core developer of pandas, a Python data analysis library. If you’d like to know more about Marc, you can check out his website which has links to his talks that he has given at PyData in Europe as well as talks at EuroPython. In fact, here is one of his talks on pandas in case you are interested: You can also see what projects he is a part of over on Github. Now, let’s take some time to get to know Marc! Can you tell us a little about yourself (hobbies, education, etc): My background is in computer engineering, with a master’s degree in AI. I wrote my first program when I was 9, and not many years later I learned about free software, and I still think it’s one of the most amazing achievements of humanity. I’ve been working professionally with Python for more than 10 years, and this year I became a Python fellow. I’m a pandas core developer, and been involved in the Python community almost since I started coding in Python. I started as a regular of the Barcelona Python meetup when we were less than 10 members in the events. I contributed to Django before it reached its 1.0. I was one of the founders of PyData Mallorca. I was a NumFOCUS ambassador. I speak regularly to PyCon and PyData conferences. And I organize the London Python Sprints group, where we mentor people who wants to contribute to open source Python projects. Most people know me for leading the pandas documentation sprint, a worldwide event last March, in which around 500 people worked on improving the pandas documentation. Around 300 pull requests were sent, I still need to review and merge some of them. 🙂 Regarding hobbies, I love hiking, travelling, yoga, playing tennis, dancing forro, playing djembe drums, and watching Bollywood movies. I don’t have time to do all that regularly, but hopefully I will at some point. Continue reading PyDev of the Week: Marc Garcia →

home/2018/10/14/ca8a2834b299553f535ee5877bc4e891c8e6a9fd.jpg

How to Provision Ubuntu 18.04 LTS Linux Servers on DigitalOcean

Python web applications need to be deployed to a production server or service so your users have access to the application.

Что нужно запомнить программисту, переходящему на Python

Когда-то давно, в студенческие годы, меня укусил питон, правда инкубационный период затянулся и получилось так, что я стал программистом на перле. Однако в какой-то момент перл исчерпал себя и я решил заняться питоном, сначала просто делал что-то и разбирался с тем, что нужно для данной задачи, а потом понял, что нужны какие-то систематизированные знания и прочитал несколько книг: Билл Любанович «Простой Python. Современный стиль программирования» Дэн Бейдер «Чистый Python. Тонкости программирования для профи» Бретт Слаткин «Секреты Python: 59 рекомендаций по написанию эффективного кода» Которые мне показались вполне подходящими для понимания основных тонкостей языка, хотя не помню, чтобы в них упоминалось про slots, но и не уверен, что это реально нужная фича — если уже по памяти прижало, то скорее всего одного этого способа будет недостаточно, но это всё зависит от ситуации. В итоге у меня накопились какие-то заметки об особенностях питона, которые, как мне кажется, могут быть полезны тому кто пожелает мигрировать на него с других языков.

Миграция схемы базы данных без даунтайма для postgresql на примере django

Введение Привет, Хабр! Хочу поделиться опытом написания миграций для postgres и django. Речь в основном пойдёт про postgres, django же здесь хорошо дополняет, так как из коробки имеет автоматическую миграцию схемы данных по изменениям модельки, то есть имеет довольно полный список рабочих операций по изменению схемы. Django можно заменить на любой любимый фрэймворк/библиотеку — подходы скорее всего будут похожи. Не буду описывать как я к этому пришёл, но сейчас читая документацию ловлю на мысли, что нужно было с большей внимательностью и осознанием делать это раньше, поэтому очень рекомендую. Перед тем как пойти дальше позволю себе сделать следующие предположения. Можно разделить логику работы с базой данных большинства приложений на 3 части: Миграции — изменение схемы базы данных (таблиц), предположим мы всегда запускаем их в один поток. Бизнес логика — непосредственная работа с данными (в пользовательских таблицах), работает с одними и теми же данными постоянно и конкурентно. Миграции данных — не изменяют схемы данных, работают по сути как бизнес логика, по умолчанию, когда будем говорить про бизнес логику, будем также подразумевать и миграции данных. Даунтайм — это состояние, когда часть нашей бизнес логики не доступна/падает/грузится на заметное для пользователя время, предположим это пару секунд. Отсутствие даунтайма может быть критическим для бизнеса условием, которого любыми усилиями нужно придерживаться.

home/2018/10/10/1ca97a1a591c6348da6c5d6a09fb79b1564d0ce8.jpg

Python Community Interview With Mike Grouchy

Mike Grouchy is one of the founders of Pycoder’s Weekly and the VP of Engineering at PageCloud, a software startup building the next generation of website creation tools. In this interview, we talk about the origin of PyCoder's, basketball, and Mike's secret projects.

home/2018/10/10/8cc539b708467c87a95f7459ac0891ce22cb2953.jpg

Python 101: Episode #28 – An intro to Testing

In this episode, you will learn the basics of using Python’s doctest and unittest modules. You can also read the chapter this video is based on here or get the book on Leanpub Related Articles Python 3 Testing: An Intro to unittest Python 102: An Intro to TDD and unittest

Python: World’s Most Popular Language in 2018

According to The Economist, Python is “becoming the world’s most popular coding language”. Here’s a chart that shows how popular the language is: There’s a lot of interesting information in that article and there’s some interesting conversation going on in this Reddit thread which is related to the article.

How to Export Jupyter Notebooks into Other Formats

When working with Jupyter Notebook, you will find yourself needing to distribute your Notebook as something other than a Notebook file. The most likely reason is that you want to share the content of your Notebook to non-technical users that don’t want to install Python or the other dependencies necessary to use your Notebook. The most popular solution for exporting your Notebook into other formats is the built-in nbconvert tool. You can use nbconvert to export to the following formats: HTML (–to html) LaTeX (–to latex) PDF (–to pdf) Reveal JS (–to slides) Markdown (md) (–to markdown) ReStructured Text (rst) (–to rst) executable script (–to script) The nbconvert tool uses Jinja templates to convert your Notebook files (.ipynb) to these other static formats. Jinja is a template engine for Python. The nbconvert tool depends on Pandoc and TeX for some of the conversions that it does. You may need to install these separately on your machine. This is documented on ReadTheDocs. Continue reading How to Export Jupyter Notebooks into Other Formats →

Older Posts