FLOSS Project Planets

Ned Batchelder: Flourish

Planet Python - Sun, 2021-01-17 13:58

Flourish is a visual toy app that draws harmonographs, sinuous curves simulating a multi-pendulum trace:

Each harmonograph is determined by a few dozen parameter values, which are chosen randomly. The number of parameters depends on the number of pendulums, which defaults to 3.

Click a thumbnail to see a larger version. The large-image pages have thumbnails of “adjacent” images. Each harmonograph is determined by a few dozen parameter values. For each parameter, four nearby values are substituted, giving four thumbnails for each parameter. Clicking an adjacent thumbnail continues your exploration of the parameter space:

The settings dialog lets you adjust the number of pendulums (which determines the number of parameters) and the kinds of symmetry you are interested in.

I started this because I wanted to understand how the parameters affected the outcome, but I was also interested to give it a purely visual design. As an engineer, it was tempting to present the values of the parameters quantitatively, but I like the simplicity of just clicking curves you like.

I repeated a trick I’ve used in other mathy visual toys: when you download a PNG file of an image, the parameter values are stored in a data island in the file. You can re-upload the image, and Flourish will extract the parameters and put you back into the parameter-space exploration at that point.

This is one of those side projects that let me use different sorts of things than I usually do: numpy, SVG, sass, Docker, and so on. I had more ideas for things to add (there is color in the code but not the UI). Maybe someday I will build them.

BTW, I am happy that my first post of 2021 is called “Flourish.” I hope it is a harbinger of things to come.

Categories: FLOSS Project Planets

Wouter Verhelst: On Statements, Facts, Hypotheses, Science, Religion, and Opinions

Planet Debian - Sun, 2021-01-17 09:03

The other day, we went to a designer's fashion shop whose owner was rather adamant that he was never ever going to wear a face mask, and that he didn't believe the COVID-19 thing was real. When I argued for the opposing position, he pretty much dismissed what I said out of hand, claiming that "the hospitals are empty dude" and "it's all a lie". When I told him that this really isn't true, he went like "well, that's just your opinion". Well, no -- certain things are facts, not opinions. Even if you don't believe that this disease kills people, the idea that this is a matter of opinion is missing the ball by so much that I was pretty much stunned by the level of ignorance.

His whole demeanor pissed me off rather quickly. While I disagree with the position that it should be your decision whether or not to wear a mask, it's certainly possible to have that opinion. However, whether or not people need to go to hospitals is not an opinion -- it's something else entirely.

After calming down, the encounter got me thinking, and made me focus on something I'd been thinking about before but hadn't fully forumlated: the fact that some people in this world seem to misunderstand the nature of what it is to do science, and end up, under the claim of being "sceptical", with various nonsense things -- see scientology, flat earth societies, conspiracy theories, and whathaveyou.

So, here's something that might (but probably won't) help some people figuring out stuff. Even if it doesn't, it's been bothering me and I want to write it down so it won't bother me again. If you know all this stuff, it might be boring and you might want to skip this post. Otherwise, take a deep breath and read on...

Statements are things people say. They can be true or false; "the sun is blue" is an example of a statement that is trivially false. "The sun produces light" is another one that is trivially true. "The sun produces light through a process that includes hydrogen fusion" is another statement, one that is a bit more difficult to prove true or false. Another example is "Wouter Verhelst does not have a favourite color". That happens to be a true statement, but it's fairly difficult for anyone that isn't me (or any one of the other Wouters Verhelst out there) to validate as true.

While statements can be true or false, combining statements without more context is not always possible. As an example, the statement "Wouter Verhelst is a Debian Developer" is a true statement, as is the statement "Wouter Verhelst is a professional Volleybal player"; but the statement "Wouter Verhelst is a professional Volleybal player and a Debian Developer" is not, because while I am a Debian Developer, I am not a professional Volleybal player -- I just happen to share a name with someone who is.

A statement is never a fact, but it can describe a fact. When a statement is a true statement, either because we trivially know what it states to be true or because we have performed an experiment that proved beyond any possible doubt that the statement is true, then what the statement describes is a fact. For example, "Red is a color" is a statement that describes a fact (because, yes, red is definitely a color, that is a fact). Such statements are called statements of fact. There are other possible statements. "Grass is purple" is a statement, but it is not a statement of fact; because as everyone knows, grass is (usually) green.

A statement can also describe an opinion. "The Porsche 911 is a nice car" is a statement of opinion. It is one I happen to agree with, but it is certainly valid for someone else to make a statement that conflicts with this position, and there is nothing wrong with that. As the saying goes, "opinions are like assholes: everyone has one". Statements describing opinions are known as statements of opinion.

The differentiating factor between facts and opinions is that facts are universally true, whereas opinions only hold for the people who state the opinion and anyone who agrees with them. Sometimes it's difficult or even impossible to determine whether a statement is true or not. The statement "The numbers that win the South African Powerball lottery on the 31st of July 2020 are 2, 3, 5, 19, 35, and powerball 14" is not a statement of fact, because at the time of writing, the 31st of July 2020 is in the future, which at this point gives it a 1 in 24,435,180 chance to be true). However, that does not make it a statement of opinion; it is not my opinion that the above numbers will win the South African powerball; instead, it is my guess that those numbers will be correct. Another word for "guess" is hypothesis: a hypothesis is a statement that may be universally true or universally false, but for which the truth -- or its lack thereof -- cannot currently be proven beyond doubt. On Saturday, August 1st, 2020 the above statement about the South African Powerball may become a statement of fact; most likely however, it will instead become a false statement.

An unproven hypothesis may be expressed as a matter of belief. The statement "There is a God who rules the heavens and the Earth" cannot currently (or ever) be proven beyond doubt to be either true or false, which by definition makes it a hypothesis; however, for matters of religion this is entirely unimportant, as for believers the belief that the statement is correct is all that matters, whereas for nonbelievers the truth of that statement is not at all relevant. A belief is not an opinion; an opinion is not a belief.

Scientists do not deal with unproven hypotheses, except insofar that they attempt to prove, through direct observation of nature (either out in the field or in a controlled laboratory setting) that the hypothesis is, in fact, a statement of fact. This makes unprovable hypotheses unscientific -- but that does not mean that they are false, or even that they are uninteresting statements. Unscientific statements are merely statements that science cannot either prove or disprove, and that therefore lie outside of the realm of what science deals with.

Given that background, I have always found the so-called "conflict" between science and religion to be a non-sequitur. Religion deals in one type of statements; science deals in another. The do not overlap, since a statement can either be proven or it cannot, and religious statements by their very nature focus on unprovable belief rather than universal truth. Sure, the range of things that science has figured out the facts about has grown over time, which implies that religious statements have sometimes been proven false; but is it heresy to say that "animals exist that can run 120 kph" if that is the truth, even if such animals don't exist in, say, Rome?

Something very similar can be said about conspiracy theories. Yes, it is possible to hypothesize that NASA did not send men to the moon, and that all the proof contrary to that statement was somehow fabricated. However, by its very nature such a hypothesis cannot be proven or disproven (because the statement states that all proof was fabricated), which therefore implies that it is an unscientific statement.

It is good to be sceptical about what is being said to you. People can have various ideas about how the world works, but only one of those ideas -- one of the possible hypotheses -- can be true. As long as a hypothesis remains unproven, scientists love to be sceptical themselves. In fact, if you can somehow prove beyond doubt that a scientific hypothesis is false, scientists will love you -- it means they now know something more about the world and that they'll have to come up with something else, which is a lot of fun.

When a scientific experiment or observation proves that a certain hypothesis is true, then this probably turns the hypothesis into a statement of fact. That is, it is of course possible that there's a flaw in the proof, or that the experiment failed (but that the failure was somehow missed), or that no observance of a particular event happened when a scientist tried to observe something, but that this was only because the scientist missed it. If you can show that any of those possibilities hold for a scientific proof, then you'll have turned a statement of fact back into a hypothesis, or even (depending on the exact nature of the flaw) into a false statement.

There's more. It's human nature to want to be rich and famous, sometimes no matter what the cost. As such, there have been scientists who have falsified experimental results, or who have claimed to have observed something when this was not the case. For that reason, a scientific paper that gets written after an experiment turned a hypothesis into fact describes not only the results of the experiment and the observed behavior, but also the methodology: the way in which the experiment was run, with enough details so that anyone can retry the experiment.

Sometimes that may mean spending a large amount of money just to be able to run the experiment (most people don't have an LHC in their backyard, say), and in some cases some of the required materials won't be available (the latter is expecially true for, e.g., certain chemical experiments that involve highly explosive things); but the information is always there, and if you spend enough time and money reading through the available papers, you will be able to independently prove the hypothesis yourself. Scientists tend to do just that; when the results of a new experiment are published, they will try to rerun the experiment, partially because they want to see things with their own eyes; but partially also because if they can find fault in the experiment or the observed behavior, they'll have reason to write a paper of their own, which will make them a bit more rich and famous.

I guess you could say that there's three types of people who deal with statements: scientists, who deal with provable hypotheses and statements of fact (but who have no use for unprovable hypotheses and statements of opinion); religious people and conspiracy theorists, who deal with unprovable hypotheses (where the religious people deal with these to serve a large cause, while conspiracy theorists only care about the unprovable hypotheses); and politicians, who should care about proven statements of fact and produce statements of opinion, but who usually attempt the reverse of those two these days


[[!img Error: Image::Magick is not installed]]

Categories: FLOSS Project Planets

Wouter Verhelst: Software available through Extrepo

Planet Debian - Sun, 2021-01-17 09:03

Just over 7 months ago, I blogged about extrepo, my answer to the "how do you safely install software on Debian without downloading random scripts off the Internet and running them as root" question. I also held a talk during the recent "MiniDebConf Online" that was held, well, online.

The most important part of extrepo is "what can you install through it". If the number of available repositories is too low, there's really no reason to use it. So, I thought, let's look what we have after 7 months...

To cut to the chase, there's a bunch of interesting content there, although not all of it has a "main" policy. Each of these can be enabled by installing extrepo, and then running extrepo enable <reponame>, where <reponame> is the name of the repository.

Note that the list is not exhaustive, but I intend to show that even though we're nowhere near complete, extrepo is already quite useful in its current state:

Free software
  • The debian_official, debian_backports, and debian_experimental repositories contain Debian's official, backports, and experimental repositories, respectively. These shouldn't have to be managed through extrepo, but then again it might be useful for someone, so I decided to just add them anyway. The config here uses the deb.debian.org alias for CDN-backed package mirrors.
  • The belgium_eid repository contains the Belgian eID software. Obviously this is added, since I'm upstream for eID, and as such it was a large motivating factor for me to actually write extrepo in the first place.
  • elastic: the elasticsearch software.
  • Some repositories, such as dovecot, winehq and bareos contain upstream versions of their respective software. These two repositories contain software that is available in Debian, too; but their upstreams package their most recent release independently, and some people might prefer to run those instead.
  • The sury, fai, and postgresql repositories, as well as a number of repositories such as openstack_rocky, openstack_train, haproxy-1.5 and haproxy-2.0 (there are more) contain more recent versions of software packaged in Debian already by the same maintainer of that package repository. For the sury repository, that is PHP; for the others, the name should give it away.

    The difference between these repositories and the ones above is that it is the official Debian maintainer for the same software who maintains the repository, which is not the case for the others.

  • The vscodium repository contains the unencumbered version of Microsoft's Visual Studio Code; i.e., the codium version of Visual Studio Code is to code as the chromium browser is to chrome: it is a build of the same softare, but without the non-free bits that make code not entirely Free Software.
  • While Debian ships with at least two browsers (Firefox and Chromium), additional browsers are available through extrepo, too. The iridiumbrowser repository contains a Chromium-based browser that focuses on privacy.
  • Speaking of privacy, perhaps you might want to try out the torproject repository.
  • For those who want to do Cloud Computing on Debian in ways that isn't covered by Openstack, there is a kubernetes repository that contains the Kubernetes stack, the as well as the google_cloud one containing the Google Cloud SDK.
Non-free software

While these are available to be installed through extrepo, please note that non-free and contrib repositories are disabled by default. In order to enable these repositories, you must first enable them; this can be accomplished through /etc/extrepo/config.yaml.

  • In case you don't care about freedom and want the official build of Visual Studio Code, the vscode repository contains it.
  • While we're on the subject of Microsoft, there's also Microsoft Teams available in the msteams repository. And, hey, skype.
  • For those who are not satisfied with the free browsers in Debian or any of the free repositories, there's opera and google_chrome.
  • The docker-ce repository contains the official build of Docker CE. While this is the free "community edition" that should have free licenses, I could not find a licensing statement anywhere, and therefore I'm not 100% sure whether this repository is actually free software. For that reason, it is currently marked as a non-free one. Merge Requests for rectifying that from someone with more information on the actual licensing situation of Docker CE would be welcome...
  • For gamers, there's Valve's steam repository.

Again, the above lists are not meant to be exhaustive.

Special thanks go out to Russ Allbery, Kim Alvefur, Vincent Bernat, Nick Black, Arnaud Ferraris, Thorsten Glaser, Thomas Goirand, Juri Grabowski, Paolo Greppi, and Josh Triplett, for helping me build the current list of repositories.

Is your favourite repository not listed? Create a configuration based on template.yaml, and file a merge request!

Categories: FLOSS Project Planets

Wouter Verhelst: SReview 0.6

Planet Debian - Sun, 2021-01-17 09:03

... isn't ready yet, but it's getting there.

I had planned to release a new version of SReview, my online video review and transcoding system that I wrote originally for FOSDEM but is being used for DebConf, too, after it was set up and running properly for FOSDEM 2020. However, things got a bit busy (both in my personal life and in the world at large), so it fell a bit by the wayside.

I've now also been working on things a bit more, in preparation for an improved administrator's interface, and have started implementing a REST API to deal with talks etc through HTTP calls. This seems to be coming along nicely, thanks to OpenAPI and the Mojolicious plugin for parsing that. I can now design the API nicely, and autogenerate client side libraries to call them.

While at it, because libmojolicious-plugin-openapi-perl isn't available in Debian 10 "buster", I moved the docker containers over from stable to testing. This revealed that both bs1770gain and inkscape changed their command line incompatibly, resulting in me having to work around those incompatibilities. The good news is that I managed to do so in a way that keeps running SReview on Debian 10 viable, provided one installs Mojolicious::Plugin::OpenAPI from CPAN rather than from a Debian package. Or installs a backport of that package, of course. Or, heck, uses the Docker containers in a kubernetes environment or some such -- I'd love to see someone use that in production.

Anyway, I'm still finishing the API, and the implementation of that API and the test suite that ensures the API works correctly, but progress is happening; and as soon as things seem to be working properly, I'll do a release of SReview 0.6, and will upload that to Debian.

Hopefully that'll be soon.

Categories: FLOSS Project Planets

Python Pool: 7 Ways in Python to Capitalize First Letter of a String

Planet Python - Sun, 2021-01-17 08:24

Hello coders!! In this article, we will be learning how one can capitalize the first letter in the string in Python. There are different ways to do this, and we will be discussing them in detail. Let us begin!

Method 1: str.capitalize() to capitalize the first letter of a string in python:
  • Syntax: string.capitalize()
  • Parameters: no parameters
  • Return Value: string with the first capital first letter
string = "python pool" print("Original string:") print(string) print("After capitalizing first letter:") print(string.capitalize()) Output & Explanation: Output

When we use the capitalize() function, we convert the first letter of the string to uppercase. In this example, the string we took was “python pool.” The function capitalizes the first letter, giving the above result.

Method 2: string slicing + upper():
  • Synatx: string.upper()
  • Parameters: No parameters
  • Return Value:  string where all characters are in upper case
string = "python pool" print("Original string:") print(string) result = string[0].upper() + string print("After capitalizing first letter:") print(result) Output & Explanation: Output

We used the slicing technique to extract the string’s first letter in this example. We then used the upper() method to convert it into uppercase.

Method 3: str.title():
  • Syntax: str.title()
  • Parameters: a string that needs to be converted
  • Return Value: String with every first letter of every word in capital
string = "python pool" print("Original string:") print(string) print("After capitalizing first letter:") print(str.title(string)) Output & Explanation: Output

str.title() method capitalizes the first letter of every word and changes the others to lowercase, thus giving the desired output.

Method 4: capitalize() Function to Capitalize the first letter of each word in a string in Python string = "python pool" print("Original string:") print(string) print("After capitalizing first letter:") result = ' '.join(elem.capitalize() for elem in string.split()) print(result) Output & Explanation: Output

In this example, we used the split() method to split the string into words. We then iterated through it with the help of a generator expression. While iterating, we used the capitalize() method to convert each word’s first letter into uppercase, giving the desired output.

Method 5: string.capwords() to Capitalize first letter of every word in Python:
  • Syntax: string.capwords(string)
  • Parameters: a string that needs formatting
  • Return Value: String with every first letter of each word in capital
import string txt = "python pool" print("Original string:") print(txt) print("After capitalizing first letter:") result = string.capwords(txt) print(result) Output & Explanation: Output

capwords() function not just convert the first letter of every word into uppercase. It also converts every other letter to lowercase.

Method 6: Capitalize the first letter of every word in the list in Python: colors=['red','blue','yellow','pink'] print('Original List:') print(colors) colors = [i.title() for i in colors] print('List after capitalizing each word:') print(colors) Output & Explanation: Output

Iterate through the list and use the title() method to convert the first letter of each word in the list to uppercase.

Method 7:Capitalize first letter of every word in a file in Python file = open('sample1.txt', 'r') for line in file: output = line.title() print(output) Output & Explanation: Python Pool Is Your Ultimate Destination For Your Python Knowledge

We use the open() method to open the file in read mode. Then we iterate through the file using a loop. After that, we capitalize on every word’s first letter using the title() method.

You might be interested in reading: Conclusion:

The various ways to convert the first letter in the string to uppercase are discussed above. All functions have their own application, and the programmer must choose the one which is apt for his/her requirement.

However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.

Happy Pythoning!

The post 7 Ways in Python to Capitalize First Letter of a String appeared first on Python Pool.

Categories: FLOSS Project Planets

Andre Roberge: Friendly contest: the race is on

Planet Python - Sun, 2021-01-17 04:07

tl; dr: Python was wrong ;-)

After one day, I've had one valid entry submitted to the contest I announced yesterday; I've also had two other submissions from the same contributor that I deemed to be invalid for the contest. The submissions shared a similar characteristics to a different degree: the information provided by Python in the exception message did not tell the whole story and, taken on its own, might have been considered to be misleading. 

One such cases which I did not considered to be valid for this contest was the error message UnboundLocalError: local variable 'x' referenced before assignment  given for code containing the following

def f():
x = 1
del x
print(x) # raises the exception

When the exception is raised, there is indeed no trace of variable "x". So while there was an assignment for such a variable before, after deletion it no longer exists. Reading this code, instead of an UnboundLocalError, the exception that should probably be raised at this point is NameError: name 'x' is not defined ; however, Friendly-traceback's role is not to second-guess Python but to explain what an exception means and, whenever possible, give more details using the information available when the exception was raised. I considered this case and another one to be beyond the scope of what Friendly-traceback could accomplish.

The entry that I deemed to be valid was based on the following code:

class F:
__slots__ = ["a"]

f = F()
f.b = 1

The error message given by Python in this case is AttributeError: 'F' object has no attribute 'b'. While technically correct, the problem is not that this object has no such attribute but that it cannot have such an attribute. This information can be easily obtained when the exception is raised and the information provided by Friendly-traceback now includes the following:

The object f has no attribute named b.
Note that object f uses __slots__ which prevents the creation of new
attributes. The following are some of its known attributes: a.

Reminder: the contest is open for 8 more days.

Categories: FLOSS Project Planets

Season of KDE 2021

Planet KDE - Sat, 2021-01-16 21:06

Hello, it has been a while, today I bring good news!

First a bit of background, I am Jean Lima Andrade, a second year student of IFBA (Federal institute of Bahia), last year I have participated on SoK 2020 and GSoC 2020. You may know me from my previous posts.

On this Season of KDE, I will be adding support for audio annotation on marK. This year, Pranav, a fellow SoK student, will also add video annotation support, I will be mentored by Caio Jordão Carvalho alongside Tomaz Canabrava. I look forward to work with all of them.

That is it, see you on the next post ; )

Categories: FLOSS Project Planets

Junichi Uekawa: Yesterday was our monthly Debian meeting.

Planet Debian - Sat, 2021-01-16 20:39
Yesterday was our monthly Debian meeting. We do one every month for Tokyo and Kansai combined, because it's online and no reason to split for now. I presented what I learnt about nodejs packaging in Debian. This time, I started using Emacs for presentation, presenting PDF file. This week I switched most of my login shells to emacsclient, and experimenting. It's interesting how much things break, and how much I depended on .bashrc and .profile being loaded. But most things work and I don't need most things outside of emacs...

Categories: FLOSS Project Planets

libsigsegv @ Savannah: libsigsegv 2.13 is released

GNU Planet! - Sat, 2021-01-16 18:14

libsigsegv version 2.13 is released.

New in this release:

  • Added support for macOS/arm64.
  • Added support for Solaris OpenIndiana.
  • Added support for catching stack overflow on Solaris 11/SPARC.
  • Added support for catching stack overflow on 64-bit Haiku.
  • Provide a correct value for SIGSTKSZ on 64-bit Solaris/x86. The one defined by this system is too small.
  • Improved support for Linux/RISC-V, Linux/nds32.
  • Improved support for Android.
  • Improved support for FreeBSD/x86, FreeBSD/x86_64, FreeBSD/arm, FreeBSD/arm64.
  • Improved support for 64-bit ABI on Solaris/x86_64.
  • NOTE: Support for Cygwin and native Windows is currently not up-to-date.

Download: https://ftp.gnu.org/gnu/libsigsegv/libsigsegv-2.13.tar.gz

Categories: FLOSS Project Planets

Christian Kastner: Keeping your Workstation Silent

Planet Debian - Sat, 2021-01-16 16:27

I require moderately powerful boxes for my work. Moderately powerful boxes generate a non-negligible amount of heat, and therefore require appropriate cooling. Most cooling solutions involve a certain degree of noise, which I dislike.

Water-cooling is supposed to be the most effective solution for noise reduction, but it always felt like too much of a hassle to try to me.

Considering the various solutions I've tried in the past years, two observations I've made really stick out:

  1. Noctua's reputation for CPU cooling is well-earned.

  2. A "silent" (meaning sound-proofed) case, isn't. At least, not anymore.

I've tried numerous coolers in the past, some of monstrous proportions (always thinking that more mass must be better, and reputable brands are equally good), but I was never really satisfied; hence, I was doubtful that trying yet another cooler would make a difference. I'm glad I tried the Noctua NH-D15 anyway. With some tweaking to the fan profile in the BIOS, it's totally inaudible at normal to medium workloads, and just a very gentle hum at full load—subtle enough to disappear in the background.

For the past decade, I've also regularly purchased sound-proofed cases, but this habit appears anachronistic now. Years ago, sound-proofed cases helped contain the noise of a few HDDs. However, all of my boxes now contain NVMe drives (which, to me, are the biggest improvement to computing since CPUs going multi-core).

On the other hand, some of my boxes now contain powerful GPUs used for GPGPU computing, and with the recent higher-end Nvidia and AMD cards all pulling in over 300W, there is a lot of heat to manage. The best way to quickly dump heat is with good airflow. Sound-proofing works against that. Its insulation restricts airflow, which ultimately causes even more noise, as the GPU's fans need to spin at very high RPMs. This is, of course, totally obvious in hindsight.

I removed the front cover from a new GPU box, and the noise went down from almost-hair-dryer to acceptable-whoosh levels. I'm wondering whether a completely open box might not be even more effective.

Categories: FLOSS Project Planets

Brian Osborne: Introducing the Decorative Image Widget Drupal module

Planet Drupal - Sat, 2021-01-16 14:01
Drupal's Problem With Decorative Images

Decorative images are those that should not be described to assistive technology like screen readers. A simple example is a fancy image of a decorative border that you insert at the end of a news article.

Categories: FLOSS Project Planets

Python Pool: cPickle in Python Explained With Examples

Planet Python - Sat, 2021-01-16 09:30

Hello geeks and welcome in this article, we will cover cPickle. Along with that, we will also look at some examples to better understand. We will also see what its application are. But before moving that ahead, let us look at the function’s definition to develop a basic understanding of it.

The cPickle module helps us by implementing an algorithm for turning an arbitrary python object into a series of Bytes. The Pickle module also carries a similar type of program. But the difference between the 2 is that cPickle is much faster and implements the algorithm in C. The only drawback of cPickle over Pickle is that it does not allow the user to subclass from Pickle. In short, we can conclude that cPickle is used with the motive of object serialization. Now in the next section, let us analyze our definition through a bunch of programs.

Application of cPickle

In this section we will see the application cPickle. The first here would be to pickle the data .


import pickle as cPickle mylist = ['apple', 'bat', 'cat', 'dog'] with open('data.txt', 'wb') as fh: cPickle.dump(mylist, fh)

Here one thing that I would like to clear is that there is no cPickle module available in the newer python version. So import the pickle module, which will automatically use the cPickle. Now coming back to the explanation of the above example. Here first, we have imported our module. After which, we have declared an array. Next, we have used the command with open and specified our file’s name. Here we have used the “wb” mode instead of “w” as all the operations need to be done using the bytes stream.

If you look at the above 2 images, you can notice that a file named data.txt is added to the left-hand side after successfully running the program. You can also see from the 1st image the outcome for importing the cPickle file. Now we are done with the creation part, but still, we can read nothing as the data is in binary form. Next, we will look at how to extract data from the file.

– Extracting data from pickle

import pickle as cPickle cPickle_off = open("data.txt", "rb") file = cPickle.load(cPickle_off) print(file)

Here from the above example, we can note that we have successfully retrieved our pickle data. To achieve this, we have opened our file “data.txt.” Then we have loaded that and eventually printed the result.

cPickle vs Pickle Comparison

This section will discuss the main difference between the cPickle and Pickle Module. The Pickle module is used to serialize and de-serialize the python object. Like the cPickle module, it converts python objects into a byte stream. Which helps in further storing it in the database. The basic difference between them is that cPickle is much faster than Pickle. This is because the cPickle implements the algorithm part in C.

Import error: no module named cPickle

This section will discuss one common error that many of us face when working with the cPickle module. The common error is “no module named cPickle found.” As I have discussed earlier, to avoid such an error, we should import the Pickle module instead of cPickle. What it does is that it automatically imports the C accelerator. So import Pickle and get rid of such errors.

You might be interested in reading: Conclusion

In this article, we looked at cPickle. We covered its definition and looked at its application through an example. We looked at the process of pickling and then retrieving the data from it. In the end, we can conclude that the cPickle module is used for object serialization.

I hope this article was able to clear all doubts. But in case you have any unsolved queries feel free to write them below in the comment section. Done reading this, why not read about the ogrid function next.

The post cPickle in Python Explained With Examples appeared first on Python Pool.

Categories: FLOSS Project Planets

Andre Roberge: Write bad code to win a prize

Planet Python - Sat, 2021-01-16 07:23



Get a chance of winning a prize by writing code with ONE error that Friendly-traceback cannot properly analyze, in one of three categories:

  • SyntaxError: invalid syntax
  • SyntaxError: some message, where some message is not recognized.
  • Any case of NameError, AttributeError, ModuleNotFoundError, UnboundLocalError, ImportError, IndexError, KeyError that is not recognized or is given an incorrect explanation by Friendly-traceback.

Submitted issues about bugs for Friendly-traceback itself are also considered for this contest.

Links: Github issue

Friendly-traceback documentation

The prize

There will be one prize given drawn randomly from all eligible submissions. The prize consists of one ebook/pbook of your choice with a maximum value of 50 USD (including delivery for pbook) as long as I can order it and have it delivered to you. Alternatively, a donation for that amount to the open source project of your choice if it can be made using Paypal.

The details

Each valid issue will get one entry for the contest. Valid issues contain code that might be expected to be written by a beginner or advanced beginner. It excludes code that uses type annotations as well as the use of async and await keywords.  The code is expected to contain ONE mistake only and not generate secondary exceptions.

The code can be run either using the friendly-console, or running in a Jupyter environment or from an editor as described in the documentation.

For a given valid submission, a bonus entry will be given if a link can be provided to an actual example from a site (such as StackOverflow, /r/python or /r/learnpython, etc.) where a question had been asked prior to this contest.

Exceptions that are not recognized by Friendly-traceback or for which the explanation (in English or French) is wrong or misleading are considered to be valid issues.

Submissions that are considered to be duplicate of previously submitted cases (because they basically have the same cause) will not be considered.

Honor code

I would ask that you do not read the source of Friendly-traceback with the sole intent of finding ways to write code that is designed to lead it to provide incorrect explanations.

End of contest

The contest will end on Monday January 25, at 8 AM Atlantic Standard Time.

Categories: FLOSS Project Planets

KDE OSM Indoor Map Demo App

Planet KDE - Sat, 2021-01-16 05:00

Last year KDE Itinerary got an indoor map view for airports and train stations, using a specialized map renderer and using raw OSM data as source. Improving that by contributing to upstream OSM data as well as our MapCSS styles now got a bit easier.

KOSMIndoorMap Demo App

The component used by KDE Itinerary for this, KOSMIndoorMap, is a library and as such not really useful without being embedded in an application. Having to create dummy itineraries covering all locations you want to check so you can look at the map is however very inconvenient e.g. when working on OSM data upstream.

To address this one of KOSMIndoorMap’s test programs has been expanded to a little stand-alone demo/test app, and more importantly, packaged for KDE’s nightly Flatpak and Android builds.


flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo flatpak remote-add --if-not-exists kdeapps --from https://distribute.kde.org/kdeapps.flatpakrepo flatpak install kdeapps org.kde.kosmindoormap


Note that this is not meant as a user-facing application at this point, and as such misses things like translations and contains a number of features only useful for contributors. It doesn’t even have all the features and controls yet the indoor map integration in KDE Itinerary has at this point.

KOSMIndoorMap standalone demo app offering different means of selecting a location.

Should somebody be interested in creating a generally useful indoor map app, that could certainly be done on top of KOSMIndoorMap (and we should talk :) ), but that’s currently not the scope here.

Reviewing OSM Data

The most important use-case for now is reviewing (and improving) OSM data. The crucial difference between regular (outdoor) maps and indoor maps is the floor level topology. Whether that data is correct is hard to judge on a map renderer that doesn’t split floors.

In OSM, floor levels are modeled using the level tag, anything not on the ground floor should have that. In the most simple case the value is just an integer number, and the most common issue is that this is missing on a few elements.

Side-by-side comparison of two floor levels showing railway tracks on the wrong level at Brussels South station.

Slightly more elaborate are elements connecting multiple floor levels, such as stairs, elevators or escalators. For those the level tag should contain a range or semi-colon separated list of floors. In our indoor map renderer this results in the ability to change floors by clicking on the corresponding element. This information being incomplete is also common, resulting in stairs only shown on a single floor for example.

Some stairs in Munich central station being non-interactive due to only being assigned to a single level.

After identifying and fixing such issues in the OSM data you should see the new data in the app within a week or two, as it propagates through the server-side and local caches.

Improving MapCSS Styling

When editing and improving our MapCSS map styles, the stand-alone app is equally useful. The app allows you to load an external MapCSS stylesheet, as well as reload one previously opened, so you get immediate feedback of your changes.

This does work fine on Linux, on Android this is a bit more complicated due to the file system sandboxing mechanisms. So I’d expect problems there when using stylesheets spread over multiple files (for which we need access to the entire directory). KDE Itinerary works around that in development mode with allowing to “upload” changed stylesheets into its internal storage space, but that’s still missing in the stand alone app.

What you get on both platforms though is the “diagnostic” style, showing the raw geometry of all elements, and the ability to show all OSM tags in the element information dialog (enable “Debug Info Model”).

Testing and Feedback

A third use-case of course is general testing of the indoor map renderer and its higher-level functions like properly identifying train station platforms or airport gates, or the matching of OSM elevator/escalator data with the corresponding realtime status information.

There’s a workboard for identified issues, proposed extensions or any other feedback.

Categories: FLOSS Project Planets

Season Of KDE - The Beginning

Planet KDE - Sat, 2021-01-16 02:31

Hello KDE Community I am Manav Sethi an engineering student from India and I got selected for Sok this year .

I will be working on creating an app for the Promo Team which will be used to post to multiple social media platforms at once. Since the Promo team Members spend time posting the same thing on multiple platforms this will definitely help in increasing their efficiency.

My mentor for this project would be Paul Brown who will be helping me deliver the Promo team's vision of this app.

P.S.: For Fans of the Popular American Sitcom The Office Yes I am creating kind of a clone of wuph.com

Categories: FLOSS Project Planets

This week in KDE: text reflow in Konsole!

Planet KDE - Sat, 2021-01-16 00:36

This week a huge new feature landed in Konsole: it now reflows the text when you resize the window! This feature can be turned off if you don’t like it, but comes on by default. It works really well. Thanks very much to Carlos Alves and Tomaz Canabrava for this work! It will be released in Konsole 21.04.

Other New Features

Gwenview now lets you optionally use a solid black color while in full screen view (Antonio Prcela, Gwenview 21.04):

Dolphin now lets you configure whether newly-opened tabs go at the end of the tab bar, or after the current tab (Anthony Fieroni, Dolphin 21.04):

Ark now supports ARJ archives (Natsumi Higa, Ark 21.04)

Bugfixes & Performance Improvements

Spectacle now lets you change the default screenshot file format when using a non-English language (Nicolas Fella, Spectacle 20.12.2)

Elisa no longer crashes when you enqueue a song accessed using the filesystem browser view (Matthieu Gallien, Elisa 20.12.2)

Adding radio streams in Elisa now works again (Sven Marquardt, Elisa 20.12.2)

Elisa’s “Show current track” button once again works (me: Nate Graham, Elisa 20.12.2)

The “Apply” button of Elisa’s settings window now activates and deactivates at the correct times (Matthieu Gallien, Elisa 21.04)

When using a vertical panel, the date displayed below the clock no longer sometimes becomes huge (Marco Martin, Plasma 5.21)

Plasma no longer freezes when an app sends many notifications in quick succession (Kai Uwe Broulik, Plasma 5.21)

Fixed various issues with Breeze theme context menu borders sometimes being invisible or pure black (David Redondo, Plasma 5.21)

The Global Menu applet now updates properly when focus is changed to or from a GTK app (David Edmundson, Plasma 5.21)

When pulling up the virtual keyboard on the login or lock screen, the password field now remains focused, so the characters you type no longer disappear into the void without manually re-focusing it first (me: Nate Graham, Plasma 5.21)

After enabling any calendar plugins in the Digital Clock, the calendar panel now appears instantly, rather than requiring Plasma to be restarted first (Nicolas Fella, Plasma 5.21)

Discover’s sidebar header no longer sometimes overlaps the contents after resizing the window (Marco Martin, Plasma 5.21)

Fixed a case where a newly-created panel could be placed on the wrong screen in a multi-screen setup (Xaver Hugl, Plasma 5.21)

KRunner once again parses and interprets hexadecimal input correctly (Alexander Lohnau, Plasma 5.21)

Country code labels in System Settings’ Keyboard page are now legible when using a light color scheme with a Dark Plasma theme (or the reverse) (me: Nate Graham, Plasma 5.21)

Aborting a change in System Setting’ Users page by canceling the authentication dialog no longer causes the changes to be applied anyway (Nicolas Fella, Plasma 5.21)

KDE Connect no longer sometimes crashes when it gets spammed with notifications (Nicolas Fella, Frameworks 5.79)

Kirigami icons in apps now consume a bit less memory, which will appreciably reduce memory usage for apps that have a lot of icons (David Edmundson, Frameworks 5.79)

User Interface Improvements

Dolphin now lets you decompress multiple archive files at a time via the context menu item (Elvis Angelaccio, Ark 20.12.2)

Ark’s preview window now closes when you hit the default “close window” shortcut (typically Ctrl+W) (Méven Car, Ark 21.04)

Ctrl+clicking on a Places panel item in Dolphin now opens it in a new tab (Kai Uwe Broulik, Dolphin 21.04)

System Settings’ Login Screen (SDDM) page has been rewritten which fixes a bunch of bugs and makes it look nicer and more consistent (David Redondo, Plasma 5.21):

It’s now possible to drag QML-based apps from empty areas of their headers and backgrounds, just like QWidgets-based apps (Marco Martin, Frameworks 5.79 with Plasma 5.21)

Plasma’s “microphone is being used” indicator now tells you which microphone is being used in its tooltip (Kai Uwe Broulik, Plasma 5.21)

System Settings’ Default Applications page now supports the “Highlight default settings” feature (Cyril Rossi, Plasma 5.21)

The Global Menu applet now respects Fitts’ law by allowing you to slide your cursor from one menu to another one on the row of pixels that is touching the screen edge (Jan Blackquill, Plasma 5.21)

System Settings’ Splash Screen page now lives in the Appearance category (me: Nate Graham, Plasma 5.21):

The “Get new Plasma Widgets” dialog now uses the much nicer new-style version (Alexander Lohnau, Plasma 5.21):

KDE apps no longer show Docker volumes in their Places panels (Méven Car, Frameworks 5.79)

How You Can Help

Have a look at https://community.kde.org/Get_Involved to discover ways to be part of a project that really matters. Each contributor makes a huge difference in KDE; you are not a number or a cog in a machine! You don’t have to already be a programmer, either. I wasn’t when I got started. Try it, you’ll like it! We don’t bite!

Finally, consider making a tax-deductible donation to the KDE e.V. foundation.

Categories: FLOSS Project Planets

Abhijith PA: Transition from Thunderbird to Mutt

Planet Debian - Fri, 2021-01-15 23:37

I was going OK with Thunderbird and enigmail(though it have many problems). Normally I go through changelogs before updating packages and rarely do a complete upgrage of my machine. Couple of days ago I did a complete upgrade of system which updated my Thunderbird to latest version and throwing of enigmail plugin for using their native openPGP support. There is a blog from Mozilla which I should’ve read earlier. Thunderbird’s builtin openPGP functionality is still in experimental, atleast not ready for my workflow. I could’ve downgrade to version 68. But I chose to move to my secondary MUA, mutt. I was using mutt for emails and newsletters that I check twice in a year a so.

So I started configuring mutt to handle my big mailboxes. It took three evenings to configure mutt to my workflow. Though the basic setup can be done in less than an hour it is the small nitpicks consumed much of my time. Currently I have isync to pull and keep mails offline. Mutt to read, msmtp to send, abook as the email address book and urlview to see the links in mail. I am still learning notmuch and virtual mailbox ways to filter.

There are ton of articles out there to configure mutt and all related things to it. But I find certain configs very hard to get. So I will write down those.

  • As a long Thunderbird user, I still want my mailbox index to look in a certain way. I used;

    set date_format="%d/%m/%y %I:%M %p" set index_format="%3C | %Z %?X?@& ? %-22.17L %-5.50s %> %-22.20D"

    This gives following order - serial number, various flags (if there is an attachment, it will shows ‘@’), sender, subject and to extreme right there will be date and time (12h local) of mail

  • If use nano to write mails you can use set editor="nano --syntax=email -r 70 -b"

    to get 70 char length and mail related syntax highlighting

  • mutt has a way to make new mail notification. The new_mail_command can be used to execute a custom script upon new mail, such as running notify-send. There are many standalone mail notifier such as mailnag, mail notification etc. It all just felt bulky for me. So I ended up making these.

    #!/bin/sh accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC")" for account in $accounts; do acc="$(echo "$account" | sed "s/.*\///")" new=$(find "$MAILBOX/$acc/Inbox/new/" -type f -newer "$MUTT/.mailsynclastrun" 2> /dev/null) newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) if [ "$newcount" -gt "0" ]; then for file in $new; do # Extract subject and sender from mail. from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//') subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n') displays="$(pgrep -a Xorg | grep -wo "[0-9]*:[0-9]\+")" for x in $displays; do export DISPLAY=$x notify-send -i $MUTT/mutt.png -t 5000 "$account received new message:" "$from: <i>$subject</i>" done done fi done touch "$MUTT/.mailsynclastrun"

    And hooked to mail_new_command. This code snippet is from lukesmith’s mutt-wizard, I barely modified to meet my need. Currently it only look in to ‘Inbox’. I need to modify to check other mailbox folders in future.

So far, everything going okay.

  • some times mbsync throws EOF and secret key not found error.
  • searching is still a pain in mutt
  • nano’s spell checker also check things which I am replying to.
More to come

Well for now I moved mail from part of the Thunderbird. But Thunderbird was more than a MUA to me. It was my RSS reader, calendar and to-do list manager. I will write more about those once I make a complete transition.

Categories: FLOSS Project Planets

Junichi Uekawa: It's been 20 years since I became a Debian Developer.

Planet Debian - Fri, 2021-01-15 19:22
It's been 20 years since I became a Debian Developer. Lots of fun things happened, and I think fondly of the team. I am no longer active for the past 10 years due to family reasons, and it's surprising that I have been inactive for that long. I still use Debian, and I still participate in the local Debian meetings.

Categories: FLOSS Project Planets

Dirk Eddelbuettel: Rcpp 1.0.6: Some Updates

Planet Debian - Fri, 2021-01-15 18:24

The Rcpp team is proud to announce release 1.0.6 of Rcpp which arrived at CRAN earlier today, and has been uploaded to Debian too. Windows and macOS builds should appear at CRAN in the next few days. This marks the first release on the new six-months cycle announced with release 1.0.5 in July. As reminder, interim ‘dev’ or ‘rc’ releases will often be available in the Rcpp drat repo; this cycle there were four.

Rcpp has become the most popular way of enhancing R with C or C++ code. As of today, 2174 packages on CRAN depend on Rcpp for making analytical code go faster and further (which is an 8.5% increase just since the last release), along with 207 in BioConductor.

This release features six different pull requests from five different contributors, mostly fixing fairly small corner cases, plus some minor polish on documentation and continuous integration. Before releasing we once again made numerous reverse dependency checks none of which revealed any issues. So the passage at CRAN was pretty quick despite the large dependency footprint, and we are once again grateful for all the work the CRAN maintainers do.

Changes in Rcpp patch release version 1.0.6 (2021-01-14)
  • Changes in Rcpp API:

    • Replace remaining few uses of EXTPTR_PTR with R_ExternalPtrAddr (Kevin in #1098 fixing #1097).

    • Add push_back and push_front for DataFrame (Walter Somerville in #1099 fixing #1094).

    • Remove a misleading-to-wrong comment (Mattias Ellert in #1109 cleaning up after #1049).

    • Address a sanitizer report by initializing two private bool variables (Benjamin Christoffersen in #1113).

    • External pointer finalizer toggle default values were corrected to true (Dirk in #1115).

  • Changes in Rcpp Documentation:

    • Several URLs were updated to https and/or new addresses (Dirk).
  • Changes in Rcpp Deployment:

    • Added GitHub Actions CI using the same container-based setup used previously, and also carried code coverage over (Dirk in #1128).
  • Changes in Rcpp support functions:

    • Rcpp.package.skeleton() avoids warning from R. (Dirk)

Thanks to my CRANberries, you can also look at a diff to the previous release. Questions, comments etc should go to the rcpp-devel mailing list off the R-Forge page. Bugs reports are welcome at the GitHub issue tracker as well (where one can also search among open or closed issues); questions are also welcome under rcpp tag at StackOverflow which also allows searching among the (currently) 2616 previous questions.

If you like this or other open-source work I do, you can sponsor me at GitHub. My sincere thanks to my current sponsors for me keeping me caffeinated.

This post by Dirk Eddelbuettel originated on his Thinking inside the box blog. Please report excessive re-aggregation in third-party for-profit settings.

Categories: FLOSS Project Planets