Quantcast
Channel: Planet Python
Viewing all 22851 articles
Browse latest View live

NumFOCUS: Chan Zuckerberg Initiative Funds Maintenance of NumFOCUS Projects


Quansight Labs Blog: A new grant for NumPy and OpenBLAS!

$
0
0

I'm very pleased to announce that NumPy and OpenBLAS just received a $195,000 grant from the Chan Zuckerberg Initiative, through its Essential Open Source Software for Science (EOSS) program! This is good news for both projects, and I'm particularly excited about the types of activities we'll be undertaking, what this will mean in terms of growing the community, and to be part of the first round of funded projects of this visionary program.

The program

The press release gives a high level overview of the program, and the grantee website lists the 32 successful applications. Other projects that got funded include SciPy and Matplotlib (it's the very first significant funding for both projects!), Pandas, Zarr, scikit-image, JupyterHub, and Bioconda - we're in good company!

Nicholas Sonofriew and Dario Taborelli, two of the people driving the EOSS program, wrote a blog post that's well worth reading about the motivations for starting this program and the 42 projects that applied and got funded: The Invisible Foundations of Biomedicine.

Read more… (5 min remaining to read)

Matt Layman: Python Tears Through Mass Spectrometry Data

$
0
0
At the November 2019 Python Frederick event, Conor Jenkins showed the group how mass spectrometry works and how Python saves huge amounts of time when processing the large amount of data produced by a mass spec analysis. The recording from the talk is available on YouTube. Check it out! Questions? Feel free to mention me on Twitter at @mblayman so I can try to respond to your question.

Kushal Das: PoC to auto attach USB devices in Qubes

$
0
0

Here is PoC based on qubesadmin API which can auto attach USB devices to any VM as required. By default Qubes auto attaches any device to the sys-usb VM, that helps with bad/malware full USB devices. But, in special cases, we may want to select special devices to be auto attached to certain VMs. In this PoC example, we are attaching any USB storage device, but, we can add some checks to mark only selected devices (by adding more checks), or we can mark few vms where no device can be attached.

I would love to see what all magical ideas you all come up with. Have fun with the code.

Btw, you can execute it in dom0 by

python3 autoattach.py

Wingware News: Wing Python IDE 7.1.3 - November 14, 2019

$
0
0

Wing 7.1.3 adds improved and expanded documentation and support for matplotlib, improves the accuracy of code warnings, fixes automatically debugging child processes on Windows with Python 3.8, fixes installing the remote agent from .rpm or .deb installations, solves several issues with runtime type introinspection, allows Open from Project and similar navigation commands from non-Browse vi mode, improves debugger reliability, and fixes about 30 other minor usability issues.


Wing 7.1.3 Screen Shot

Download Wing 7.1.3 Now:Wing Pro | Wing Personal | Wing 101 | Compare Products


Some Highlights of Wing 7.1


Support for Python 3.8

Wing 7.1 supports editing, testing, and debugging code written for Python 3.8, so you can take advantage of assignment expressions and other improvements introduced in this new version of Python.

Improved Code Warnings

Wing 7.1 adds unused symbol warnings for imports, variables, and arguments found in Python code. This release also improves code warnings configuration, making it easier to disable unwanted warnings.

Cosmetic Improvements

Wing 7.1 improves the auto-completer, project tool, and code browser with redesigned icons that make use of Wing's icon color configuration. This release also improves text display on some Linux systems, supports Dark Mode on macOS, and improves display of Python code and icons found in documentation.

And More

Wing 7.1 also adds a How-To for using Wing with Docker, the ability to disable code warnings from tooltips on the editor, support for macOS 10.15 (Catalina), code folding in JSON files, word wrapping for output in the Testing tool, support for Windows 10 native OpenSSH installations for remote development, and many minor improvements. This release drops support for macOS 10.11. System requirements remain unchanged on Windows and Linux.

For details see the change log.

For a complete list of new features in Wing 7, see What's New in Wing 7.


Try Wing 7.1 Now!


Wing 7.1 is an exciting new step for Wingware's Python IDE product line. Find out how Wing 7.1 can turbocharge your Python development by trying it today.

Downloads:Wing Pro | Wing Personal | Wing 101 | Compare Products

See Upgrading for details on upgrading from Wing 6 and earlier, and Migrating from Older Versions for a list of compatibility notes.

Vinay Sajip (Logging): A Qt GUI for logging

$
0
0

A question that comes up from time to time is about how to log to a GUI application. The Qt framework is a popular cross-platform UI framework with Python bindings using PySide2 or PyQt5 libraries.


The following example shows how to log to a Qt GUI. This introduces a simple QtHandler class which takes a callable, which should be a slot in the main thread that does GUI updates. A worker thread is also created to show how you can log to the GUI from both the UI itself (via a button for manual logging) as well as a worker thread doing work in the background (here, just logging messages at random levels with random short delays in between).

The worker thread is implemented using Qt’s QThread class rather than the threading module, as there are circumstances where one has to use QThread, which offers better integration with other Qt components.

The code should work with recent releases of either PySide2 or PyQt5. You should be able to adapt the approach to earlier versions of Qt. Please refer to the comments in the code snippet for more detailed information.

importdatetimeimportloggingimportrandomimportsysimporttime# Deal with minor differences between PySide2 and PyQt5try:fromPySide2importQtCore,QtGui,QtWidgetsSignal=QtCore.SignalSlot=QtCore.SlotexceptImportError:fromPyQt5importQtCore,QtGui,QtWidgetsSignal=QtCore.pyqtSignalSlot=QtCore.pyqtSlotlogger=logging.getLogger(__name__)## Signals need to be contained in a QObject or subclass in order to be correctly# initialized.#classSignaller(QtCore.QObject):signal=Signal(str,logging.LogRecord)## Output to a Qt GUI is only supposed to happen on the main thread. So, this# handler is designed to take a slot function which is set up to run in the main# thread. In this example, the function takes a string argument which is a# formatted log message, and the log record which generated it. The formatted# string is just a convenience - you could format a string for output any way# you like in the slot function itself.## You specify the slot function to do whatever GUI updates you want. The handler# doesn't know or care about specific UI elements.#classQtHandler(logging.Handler):def__init__(self,slotfunc,*args,**kwargs):super(QtHandler,self).__init__(*args,**kwargs)self.signaller=Signaller()self.signaller.signal.connect(slotfunc)defemit(self,record):s=self.format(record)self.signaller.signal.emit(s,record)## This example uses QThreads, which means that the threads at the Python level# are named something like "Dummy-1". The function below gets the Qt name of the# current thread.#defctname():returnQtCore.QThread.currentThread().objectName()## Used to generate random levels for logging.#LEVELS=(logging.DEBUG,logging.INFO,logging.WARNING,logging.ERROR,logging.CRITICAL)## This worker class represents work that is done in a thread separate to the# main thread. The way the thread is kicked off to do work is via a button press# that connects to a slot in the worker.## Because the default threadName value in the LogRecord isn't much use, we add# a qThreadName which contains the QThread name as computed above, and pass that# value in an "extra" dictionary which is used to update the LogRecord with the# QThread name.## This example worker just outputs messages sequentially, interspersed with# random delays of the order of a few seconds.#classWorker(QtCore.QObject):@Slot()defstart(self):extra={'qThreadName':ctname()}logger.debug('Started work',extra=extra)i=1# Let the thread run until interrupted. This allows reasonably clean# thread termination.whilenotQtCore.QThread.currentThread().isInterruptionRequested():delay=0.5+random.random()*2time.sleep(delay)level=random.choice(LEVELS)logger.log(level,'Message after delay of %3.1f: %d',delay,i,extra=extra)i+=1## Implement a simple UI for this cookbook example. This contains:## * A read-only text edit window which holds formatted log messages# * A button to start work and log stuff in a separate thread# * A button to log something from the main thread# * A button to clear the log window#classWindow(QtWidgets.QWidget):COLORS={logging.DEBUG:'black',logging.INFO:'blue',logging.WARNING:'orange',logging.ERROR:'red',logging.CRITICAL:'purple',}def__init__(self,app):super(Window,self).__init__()self.app=appself.textedit=te=QtWidgets.QPlainTextEdit(self)# Set whatever the default monospace font is for the platformf=QtGui.QFont('nosuchfont')f.setStyleHint(f.Monospace)te.setFont(f)te.setReadOnly(True)PB=QtWidgets.QPushButtonself.work_button=PB('Start background work',self)self.log_button=PB('Log a message at a random level',self)self.clear_button=PB('Clear log window',self)self.handler=h=QtHandler(self.update_status)# Remember to use qThreadName rather than threadName in the format string.fs='%(asctime)s %(qThreadName)-12s %(levelname)-8s %(message)s'formatter=logging.Formatter(fs)h.setFormatter(formatter)logger.addHandler(h)# Set up to terminate the QThread when we exitapp.aboutToQuit.connect(self.force_quit)# Lay out all the widgetslayout=QtWidgets.QVBoxLayout(self)layout.addWidget(te)layout.addWidget(self.work_button)layout.addWidget(self.log_button)layout.addWidget(self.clear_button)self.setFixedSize(900,400)# Connect the non-worker slots and signalsself.log_button.clicked.connect(self.manual_update)self.clear_button.clicked.connect(self.clear_display)# Start a new worker thread and connect the slots for the workerself.start_thread()self.work_button.clicked.connect(self.worker.start)# Once started, the button should be disabledself.work_button.clicked.connect(lambda:self.work_button.setEnabled(False))defstart_thread(self):self.worker=Worker()self.worker_thread=QtCore.QThread()self.worker.setObjectName('Worker')self.worker_thread.setObjectName('WorkerThread')# for qThreadNameself.worker.moveToThread(self.worker_thread)# This will start an event loop in the worker threadself.worker_thread.start()defkill_thread(self):# Just tell the worker to stop, then tell it to quit and wait for that# to happenself.worker_thread.requestInterruption()ifself.worker_thread.isRunning():self.worker_thread.quit()self.worker_thread.wait()else:print('worker has already exited.')defforce_quit(self):# For use when the window is closedifself.worker_thread.isRunning():self.kill_thread()# The functions below update the UI and run in the main thread because# that's where the slots are set up@Slot(str)defupdate_status(self,status,record):color=self.COLORS.get(record.levelno,'black')s='<pre><font color="%s">%s</font></pre>'%(color,status)self.textedit.appendHtml(s)@Slot()defmanual_update(self):# This function uses the formatted message passed in, but also uses# information from the record to format the message in an appropriate# color according to its severity (level).level=random.choice(LEVELS)extra={'qThreadName':ctname()}logger.log(level,'Manually logged!',extra=extra)@Slot()defclear_display(self):self.textedit.clear()defmain():QtCore.QThread.currentThread().setObjectName('MainThread')logging.getLogger().setLevel(logging.DEBUG)app=QtWidgets.QApplication(sys.argv)example=Window(app)example.show()sys.exit(app.exec_())if__name__=='__main__':main()

Paolo Amoroso: Two Books About the Kivy GUI Framework

$
0
0
The Kivy Python GUI framework is intriguing.

Not only it’s cross-platform but also supports Android. Java is too verbose and low level for me and Kivy is an opportunity for developing native Android apps without leaving Python.

Outside of the Kivy project documentation, there are few third-party advanced tutorials that go in more depth than the official tutorials. So, before diving into the code of the Kivy demos, I wanted some books to explore more features and get a broader picture of the framework and what it can do.

I found two potentially interesting books: Building Android Apps in Python Using Kivy with Android Studio: With Pyjnius, Plyer, and Buildozer by Ahmed Fawzy Mohamed Gad (Apress, 2019), and Kivy - Interactive Applications and Games in Python - Second Edition by Roberto Ulloa (Packt, 2015).

I read both and here are my impressions.

Building Android Apps in Python Using Kivy with Android Studio

I had much hope for Building Android Apps in Python Using Kivy with Android Studio as its focus is Android. And it was published just a few weeks ago, so it may be the most up to date of the books about the framework.

But I don’t recommend the book.

Cover of Building Android Apps in Python Using Kivy with Android Studio in Google Play Books on a Pixel 2 XL
The cover of Building Android Apps in Python Using Kivy with Android Studio in Google Play Books on my Pixel 2 XL.

It’s poorly edited, often repetitive, and, despite the size, covers only a handful of widgets, layouts, and Kivy features. The few interesting tidbits here and there aren't worth the price.

As a non-native English speaker and author I face the same difficulties in writing about complex technical topics in an unfamiliar language. Had the book been self-published, I wouldn’t have minded some editing issues. But I hold a large publishing house to higher standards.

The book presents a few sample apps it progressively builds on and enhances. In most cases, each new version includes the full source code of the previous versions, which sometimes makes it difficult to spot new or changed features. This, along with the poor editing, makes reading bumpy.

Kivy with Android Studio is an oxymoron. The point of using Python to develop Android apps is to not have to use Java, so this part of the book is useless to me. I’d prefer more examples of what Plyer can do without Java.

Despite all this, the author knows his stuff. I hope for a new, improved edition that keeps the focus on Android and Python, tells how to make apps responsive on a variety of screens, expands on Plyer, and drops Java.

Kivy - Interactive Applications and Games in Python

Kivy - Interactive Applications and Games in Python is the learning resource I was looking for.

At over half the size of Gad’s book, Ulloa’s is much better. It covers many more Kivy features that help develop complex, attractive, responsive apps with a wide variety of layouts and widgets.

Cover of Kivy - Interactive Applications and Games in Python in Google Play Books on a Pixel 2 XL
The cover of Kivy - Interactive Applications and Games in Python in Google Play Books on my Pixel 2 XL.

Aside from a game, the book discusses apps that showcase several advanced widgets and features of desktop and mobile user interfaces. The sample apps display fairly complex data, have a variety of user interface controls, and showcase different interaction techniques.

Ulloa anticipates the learning roadblocks and difficulties and clarifies some subtleties of Kivy. For example, code like this in the KV file of Kivy’s reStructured Text editor demo had me puzzled as it has the same identifier at both sides of a statement:

Root:
    text_input: text_input

Ulloa explains the left one is a widget attribute, the right one a widget ID. To avoid confusion, he uses a different style in which IDs start with an underscore, like this in the previous example:

Root:
    text_input: _text_input

According to the Kivy blog’s review of Kivy – Interactive Applications and Games in Python, the chapter on events and event binding is dense and difficult to grok. As a Kivy and Python beginner this wasn’t my impression. However, the coordinate transformations that event handlers often perform may be difficult to visualize.

The code fragments are often short and easy to follow but the book has a formatting issue that interferes with reading the code. In the ePub version of the ebook I bought at Google Play Books, the width of source code blocks is too narrow and most of the lines wrap.

Ulloa’s book covers enough building blocks to bootstrap my understanding of Kivy and continue on my own.

Python Bytes: #156 All the programming LOLs


Catalin George Festila: Python 3.7.5 : About PEP 506.

$
0
0
Today I did a python evaluation and saw that there are many new aspects that should be kept in mind for a programmer. So I decided to recall some necessary elements of PEP. First, PEP stands for Python Enhancement Proposal. A PEP is a design document providing information to the Python community, or describing a new feature for Python or its processes or environment. My list will not follow a

Catalin George Festila: Python 3.7.5 : About PEP 8016.

$
0
0
Let's start with PEP 8012 which proposes a new model of Python governance based on consensus and voting, without the role of a centralized singular leader or a governing council and was rejected. The PEP 8015 formalize the current organization of the Python community and proposes changes. This PEP 8015 was rejected by a core developer vote described in PEP 8001 on Monday, December 17, 2018. The

NumFOCUS: 2019 NumFOCUS Awards and New Contributor Recognition

Weekly Python StackOverflow Report: (cciii) stackoverflow python report

$
0
0

Codementor: How to Extract Data from PDF to Excel

$
0
0
The Portable Document Format (PDF) is a file format developed by Adobe to present documents, including text formatting and images, in a manner independent of application software, hardware, and&hellip;

Ian Ozsvald: “Higher Performance Python” at PyDataCambridge 2019

$
0
0

I’ve had the pleasure of speaking at the first PyDataCambridge conference (2019), this is the second PyData conference in the UK after PyDataLondon (which colleagues and I co-founded 6 years back). I’m super proud to see PyData spread to 6 regional meetups and now 2 UK conferences.

I spoke on Higher Performance Python with a focus towards making Pandas operations go faster and an eye on the upcoming Second Edition of our High Performance Python (O’Reilly) book. The talk covers:

  • Using line_profiler to evaluate sklearn’s LinearRegression vs NumPy’s lstsq (spoiler – lstsq is much faster but that’s due to sklearn being much safer, the slow-down is all due to safety code in sklearn that helps keep your productivity higher overall)
  • Using Pandas for line-by-line iteration (slow) vs apply (faster) and apply with raw=True to expose NumPy arrays (fastest)
  • Using Numba to JIT compile lstsq using apply with raw=True for a huge speed-up
  • Using Dask to parallelise the Numba solution for further speed-ups
  • Advice on being a “highly performant data scientist”

The last point is important – going “compiler happy” and writing highly efficient code may well slow down your team and your overall velocity. Amongst other items I recommended profiling first, maybe introducing Dask& Numba only with a team’s consent and looking at tools like Bulwark to add tests to DataFrames to avoid being derailed by strange data bugs.

Right now Micha and I are busily working to complete the second edition of our book, all going well it’ll be in for Christmas with a publication date around April 2020.

 


Ian is a Chief Interim Data Scientist via his Mor Consulting. Sign-up for Data Science tutorials in London and to hear about his data science thoughts and jobs. He lives in London, is walked by his high energy Springer Spaniel and is a consumer of fine coffees.

The post “Higher Performance Python” at PyDataCambridge 2019 appeared first on Entrepreneurial Geekiness.

Python Circle: The simplest explanation of Decorators in Python

$
0
0
The simplest explanation of Decorators in Python, decorator example in python, what is a decorator, simple example decorator, decorator for a newbie, python decorators, changing function behavior without changing content, decorators

Full Stack Python: Basic Data Types in Python 3: Booleans

$
0
0

Welcome back to our ongoing series of blog posts on basic data types in Python 3! Last time, we explored the functionality of strings. Today, we dive in to another key data type - booleans. Booleans (and "boolean logic") are an important concept in programming, representing the concept of "true" and "false".

If you're learning Python, you might also want to check out TwilioQuest 3. You'll learn about basic data types like the boolean, and much more about Python programming.

Ready to learn how to use booleans in Python 3? Let's get started!

Booleans in Python 3

Booleans are a concept that exists in every programming language. A boolean represents the idea of "true" or "false". When you are writing a program, there are often circumstances where you want to execute different code in different situations. Booleans enable our code to do just that.

You can declare a boolean value in your code using the keywords True and False (note the uppercase). The following code would create two boolean values and assign them to variables.

mullet_looks_good=Falsepython_is_fun=True

More commonly, a boolean value is returned as a result of some kind of comparison. The following code example would store a boolean value of False in the have_same_name variable after using the equality comparison operator, the == symbol.

my_name="Wammu"your_name="Kars"have_same_name=my_name==your_name

Boolean logic

Booleans are used in your code to make it behave differently based on current conditions within your program. You can use boolean values and comparisons in conjunction with the if, elif, and else keyoards as one means to achieve this.

my_age=10ifmy_age>=100:print("One hundred years old! Very impressive.")elifmy_age<=3:print("Awwww. Just a baby.")else:print("Ah - a very fine age indeed")

In addition to testing for truth, you can also check if conditions are not true using the not keyword.

favorite_team="Vikings"ifnotfavorite_team=="Vikings":print("Oh - how unfortunate.")else:print("Skol, Vikings!")

More complex boolean logic

Sometimes you will need to evaluate multiple conditions in your boolean logic. For this purpose, you'll combine the and and or keywords. The and keyword compares two boolean values and returns True if both are true. The or keyword compares two values and returns True if any of the statements are true.

Let's look at an example. That uses the in keyword to see if a string is inside a list of values (we'll cover lists in a future article).

favs=["Donatello","Raphael"]if"Michelangelo"infavsand"Donatello"infavs:print("Those are my favorite ninja turtles too!")elif"Michelangelo"infavsor"Donatello"infavs:print("Well, one out of two isn't bad...")else:print("Huh - not what I would have chosen.")

Wrapping up

Booleans are an important tool in any programming language. Using boolean logic, your code can react to data inside your program, and carry out different instructions under different circumstances. Hopefully, you've learned a bit about how to work with booleans in Python 3! Stay tuned for more blog posts in this series to learn more about basic data types like strings, numbers, booleans, lists, and dictionaries.

Also, be sure to download and play TwilioQuest 3 to learn even more about Python!

Ian Ozsvald: Training Courses for 2020 Q1 – Successful Data Science Projects & Software Engineering for Data Scientists

$
0
0

Early next year I run new iterations of two of my existing training courses for Pythonic Data Scientists:

Successful Data Science Projects focuses on reducing uncertainty in a new data science project. We’ll look at the reasons why these projects can fail (and heck – this is research – they can and occasionally should fail), review ways to derisk a project with tools you’re probably not yet using, plan out a Project Specification for agreement with stakeholders and review techniques to make your team more highly performant overall.

“After attending the course I can identify and communicate to the project team and client the uncertainties of the project efficiently. I am using the techniques covered on the course to write project initiation documents and put in place the necessary processes to reduce uncertainty. The course was very engaging and I was very happy to learn from Ian’s experience to ensure a successful delivery on all future projects.”– Dani Papamaximou, Data Scientist at Arcadia

Software Engineering for Data Scientists is a 2 day course aimed at data scientists (perhaps from an academic background) who lack strong software engineering skills. We cover reviewing “bad Notebook code”, refactoring this code, using a standardised folder structure (with cookiecutter), adding unit tests and defensive Pandas tests along with checking how to introduce these techniques back into your team.

“Ian’s Software Engineering for Data Scientists course provides an excellent overview of best practices with focus on testing, debugging and general code maintenance. Ian has a wealth of experience and also makes sure to keep on top of the latest tools and libraries in the Data Science world. I would especially recommend the course to Data Science practitioners coming from an academic rather than software engineering background.”– LibertyGlobal Mirka

I am also thinking of introducing a High Performance Python course based on the updates coming to the 2nd edition of my High Performance Python book (for release April 2020). You’ll get details about this on my low-frequency email training list and if you have strong thoughts about this, please get in contact!


Ian is a Chief Interim Data Scientist via his Mor Consulting. Sign-up for Data Science tutorials in London and to hear about his data science thoughts and jobs. He lives in London, is walked by his high energy Springer Spaniel and is a consumer of fine coffees.

The post Training Courses for 2020 Q1 – Successful Data Science Projects & Software Engineering for Data Scientists appeared first on Entrepreneurial Geekiness.

ABlog for Sphinx: ABlog v0.10 released

$
0
0

ABlog v0.10 is released with the main focus being to support the latest version of Sphinx as well as Python 3 only support.

Ablog V0.9.X will no longer be supported as Python 2 comes to an end in a few months and it is time people upgraded.

Pull Requests Merged in:

Overhaul of package underneath for python3 only from nabobalis.

Add validation for conf.py entries from rayalan.

System Message: INFO/1 (/home/docs/checkouts/readthedocs.org/user_builds/ablog/checkouts/latest/docs/release/ablog-v0.10-released.rst, line 2); backlink

Duplicate explicit target name: “rayalan”.

Deploy improve from rayalan.

System Message: INFO/1 (/home/docs/checkouts/readthedocs.org/user_builds/ablog/checkouts/latest/docs/release/ablog-v0.10-released.rst, line 2); backlink

Duplicate explicit target name: “nabobalis”.

Get ablog ready for 0.10 from nabobalis.

Codementor: How and why I built Sudoku Solver

tryexceptpass: Unconventional Secure and Asynchronous RESTful APIs using SSH

$
0
0

Some time ago, in a desperate search for asynchronicity, I came across a Python package that changed the way I look at remote interfaces: AsyncSSH.

Reading through their documentation and example code, you’ll find an interesting assortment of use cases. All of which take advantage of the authentication and encryption capabilities of SSH, while using Python’s asyncio to handle asynchronous communications.

Thinking about various applications I’ve developed over the years, many included functions that could benefit from decoupling into separate services. But at times, I would avoid it due to security implications.

I wanted to build informative dashboards that optimize maintenance tasks. But they bypassed business logic, so I wouldn’t dare expose them over the same interfaces. I even looked at using HTTPS client certs, but support from REST frameworks seemed limited.

I realized that asyncssh could provide the extra security I was looking for over a well known key-based system. And in my never-ending quest to find what makes things tick, I decided to take a stab at writing a REST-ish service over SSH.

A great way to familiarize myself with the library and the protocol, it helped me learn more about building asynchronous apps, creating a small framework called korv.

Viewing all 22851 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>