OpenLLM-France/wikimedia huggingface dataset:
# Python Programming/Errors

| Previous: Modules | Index | Next: Exceptions |
In python there are three types of errors; syntax errors, logic errors and exceptions.

## Syntax errors

Syntax errors are the most basic type of error. They arise when the Python parser is unable to understand a line of code. Syntax errors are almost always fatal, i.e. there is almost never a way to successfully execute a piece of code containing syntax errors. Some syntax errors can be caught and handled, like eval(""), but these are rare.
In IDLE, it will highlight where the syntax error is. Most syntax errors are typos, incorrect indentation, or incorrect arguments. If you get this error, try looking at your code for any of these.

## Logic errors

These are the most difficult type of error to find, because they will give unpredictable results and may crash your program. A lot of different things can happen if you have a logic error. However these are very easy to fix as you can use a debugger, which will run through the program and fix any problems.
A simple example of a logic error can be showcased below, the while loop will compile and run however, the loop will never finish and may crash Python:
Logic errors are only erroneous in the perspective of the programming goal one might have; in many cases Python is working as it was intended, just not as the user intended. The above while loop is functioning correctly as Python is intended to, but the exit condition the user needs is missing.

## Exceptions

Exceptions arise when the python parser knows what to do with a piece of code but is unable to perform the action. An example would be trying to access the internet with python without an internet connection; the python interpreter knows what to do with that command but is unable to perform it.

### Dealing with exceptions

Unlike syntax errors, exceptions are not always fatal. Exceptions can be handled with the use of a try statement.
Consider the following code to display the HTML of the website 'example.com'. When the execution of the program reaches the try statement it will attempt to perform the indented code following, if for some reason there is an error (the computer is not connected to the internet or something) the python interpreter will jump to the indented code below the 'except:' command.
Another way to handle an error is to except a specific error.
If the user enters a numeric value as his/her age, the output should look like this:
However, if the user enters a non-numeric value as his/her age, a ValueError is thrown when trying to execute the int method on a non-numeric string, and the code under the except clause is executed:
You can also use a try block with a while loop to validate input:
The program will prompt you for your age until you enter a valid age:
In certain other cases, it might be necessary to get more information about the exception and deal with it appropriately. In such situations the except as construct can be used.
| Previous: Modules | Index | Next: Exceptions |
# Python Programming/Excel

Python has multiple 3rd party libraries for reading and writing Microsoft Excel spreadsheet files, including .xls and .xlsx.
For working with .xls files, there is xlrd for reading and xlwt for writing.
For working with .xlsx files, there is xlrd for reading, openpyxl for reading and writing, and XlsxWriter and PyExcelerate for writing.
To interact with the Excel application and create Python-based add-ins: xlwings, xlOil, PyXLL (commercial).

## xlrd

Supports reading .xls Excel files. Support for .xlsx files was removed in xlrd version 2.0.0 from Dec 2020 due to security concerns, but is still available in xlrd version 1.2.0 from Dec 2018. License: BSD.
Example:
Links:
* xlrd, pypi.python.org
* xlrd 1.2.0, pypi.python.org
* xlrd documentation, readthedocs.io
* xlrd API documentation, readthedocs.io
* Python: xlrd discerning dates from floats, stackoverflow.com
* xlrd.biffh.XLRDError: Excel xlsx file; not supported, 11 Dec 2020, stackoverflow.com
* xlrd 2 released, 11 Dec 2020, groups.google.com

## xlwt

Supports writing .xls files. License: BSD.
Links:
* xlwt, pypi.python.org
* xlwt documentation, readthedocs.io

## openpyxl

Supports reading and writing .xlsx Excel files. Does not support .xls files. License: MIT.
Reading a workbook:
Creating a new workbook:
Changing an existing workbook:
Links:
* openpyxl, pypi.org
* openpyxl - A Python library to read/write Excel 2010 xlsx/xlsm files, readthedocs.io

## XlsxWriter

Supports writing of .xlsx files. License: BSD.
Links:
* XlsxWriter, pypi.org
* Creating Excel files with Python and XlsxWriter, readthedocs.io

## PyExcelerate

Supports writing .xlsx files. License: BSD.
Links:
* PyExcelerate, pypi.org

## xlutils

Supports various operations and queries on .xls files; depends on xlrd and xlwt. License: MIT.
Links:
* xlutils, pypi.org

## xlOil

Supports creation of Python-based Excel add-ins. Requires Python 3.6 or later; requires Excel 2010 or later installed. Supports: global and local scope worksheet functions, ribbon customisation, custom task panes, RTD/async functions, numpy, matplotlib, pandas, jupyter. Low overhead function calls due to use of the Excel's C-API and embedded in-process Python
Examples:
Create a function to add one day to a date:
Create a function which give a live ticking clock in an cell (uses RTD):
Links:
* xlOil, pypi.org
* xloil, readthedocs.io

## pywin32

Supports access to Windows applications via Windows Component Object Model (COM). Thus, on Windows, if Excel is installed, PyWin32 lets you call it from Python and let it do various things. You can install PyWin32 by downloading a .exe installer from SourceForge, where it is currently hosted.
Links:
* 3.4.1. PyWin32, docs.python.org
* pywin32, pypi.org
* Python for Windows Extensions files, sourceforge.net
* Python Excel Mini Cookbook, pythonexcels.com

## External links

* Working with Excel Files in Python, python-excel.org -- has links to source code repositories (GitHub, etc.) for the packages
# Python Programming/Development Environments

| Previous: Getting Python | Index | Next: Interactive mode |
You can edit Python source code files in any plain text editor such as Notepad, Notepad++ or Vim. However, there are multiple integrated development environments (IDEs) available for Python. A full list can be found on the Python wiki.

## Visual Studio Code

There is a Python extension for Visual Studio Code, a popular cross-platform code editor.
Links:
* Python in Visual Studio Code, code.visualstudio.com

## Eclipse

You can use the Eclipse IDE as your Python IDE. The only requirement is Eclipse and the Eclipse PyDev Plug-in.
Go to http://www.eclipse.org/downloads/ and get the proper Eclipse IDE version for your OS platform. There are also updates on the site, but just look for the basic program, Download and install it. The install just requires you to unpack the downloaded Eclipse install file onto your system.
You can install PyDev Plug-in two ways:
* Suggested: Use Eclipse's update manager, found in the tool bar under "Help" -> "install new Software". add http://pydev.org/updates/ in "work with" click add, and select PyDev ,and click "Next" and let Eclipse do the rest. Eclipse will now check for any updates to PyDev when it searches for updates.
** If you get an error stating a requirement for the plugin "org.eclipse.mylyn", expand the PyDev tree, and deselect the optional mylyn components.
* Or install PyDev manually, by going to http://pydev.sourceforge.net and get the latest PyDev Plug-in version. Download it, and install it by unpacking it into the Eclipse base folder.

## Emacs

There is a Python mode for Emacs which provides features such as running pieces of code, and changing the tab level for blocks.
Links:
* python-mode, gitlab.com

## External links

* Integrated Development Environments, wiki.python.org
| Previous: Getting Python | Index | Next: Interactive mode |
# Perl Programming/Keywords/keys
## The keys keyword

The keys command returns all the keys the HASH has in an apparent random order, when called in list context. In Perl 5.12.0 or later, the indices of an ARRAY are returned.
As a side effect, keys resets the internal iterator of the ARRAY or HASH (see each). Calling it in void context resets the iterator with no other overhead.

### See also

* each
* values
# Perl Programming/Keywords/kill
## The kill keyword

The kill command sends a signal to a LIST of processes. Returns the number of arguments that were successfully used to signal. This is not necessarily the same as the number of processes actually killed, as a process group can also be killed. SIGNAL is either a name of a signal, or a signal number.
If the signal name is negative, it is the same as a negative number and kills a group of processes.
If SIGNAL is either 0, the string SIGZERO, or ZERO, no signal is sent to the process, but the command checks whether it's possible to send a signal to it. This is useful to check that a child process is still alive with the same UID.
# Perl Programming/Keywords/length
## The length keyword

length is a function that returns how long the following expression is in terms of characters. If no EXPRESSION is given, it returns the length of $_. If the expression is undefined, undef is returned.
As length returns the number of logical characters, to find out the number of bytes in UTF-8, one has to enter an expression (see below).

### Examples

The result is the string $name, and the length of it both as logical characters & as UTF-8.
# Perl Programming/Keywords/lcfirst
## The lcfirst keyword

lcfirst returns EXPRESSION with the first character in lowercase.

### See also

* ucfirst
# Perl Programming/Keywords/int
## The int keyword

int returns the integer part of EXPRESSION or, if EXPRESSION is not specified, that of $_.
This function is inappropriate for rounding, as it truncates towards 0, and the machine-representation of floating-point numbers could return non-intuitive results.
# Perl Programming/Keywords/ioctl
## The ioctl keyword

ioctl implements the UNIX function ioctl(2) that manipulates the underlying device parametres of special files. Many operating characteristics of character special files (like terminals) can be controlled with ioctl requests. The argument FILEHANDLE must be an open file descriptor.
To run this function, one may first request "sys/ioctl.ph";. SCALAR is read or written, depending on the FUNCTION.
The function returns undef, if the operating system returns -1; if the OS returns 0, this function returns the string "0 but true", and the returned number from the OS otherwise.
# Perl Programming/Keywords/join
## The join keyword

join joins the elements of LIST with the separators from EXPRESSION. The new string is returned.

### See also

* split
# Perl Programming/Keywords/last
## The last keyword

last is the same as break in C-like languages and is used to make the program immediately exit the current loop. Withou LABEL, the innermost loop is assumed. From Perl 5.18.0 onwards, it is possible to compute the LABEL during runtime by passing an EXPRESSION.
If a loop has a last command, the continue block is skipped.
last cannot be used to exit a block that returns a value (as it is the case with do, eval, orsub. It should not be used to exit a grep or map operation.

### See also

* continue
* next
* redo
# Perl Programming/Keywords/lc
## The lc keyword

lc is a function that returns a lowercased version of the EXPRESSION. If no EXPRESSION has been entered, $_ contents are used. The result depends on which code is used for the strings on the system.
# Perl Programming/Keywords/le
## The le keyword

le is a relational operator that returns 1 for true, if the lefthand side is stringwise less than or equal to the righthand side, and an empty string ("") for false.
# Practical Electronics/Series RL

A circuit of two components R and L connected in series
Natural Response of the cicuit can be obtained by setting the differential equation of the circuit to zero
    $v_{L}+v_{R}=0$
    $L{\frac {dI}{dt}}+IR=0$
    ${\frac {dI}{dt}}=-{\frac {1}{T}}I$
    $\int {\frac {dI}{I}}=-{\frac {1}{T}}\int dt$
    $LnI=-{\frac {1}{T}}+C$
    $I=e^{(-{\frac {1}{T}}+C)}$
    $I=Ae^{-{\frac {t}{T}}}$
    $T={\frac {L}{R}}$
    $e^{C}=IR$
# Practical Electronics/Series RLC

A circuit of 3 components connected in series

## Circuit's response
### Equilibrium Response

At Equilibrium, the sum of all voltages equal to zero
    $v_{L}+v_{C}+v_{R}=0$
    $L{\frac {di}{dt}}+{\frac {1}{C}}\int idt+iR=0$
    ${\frac {d^{2}i}{dt^{2}}}+{\frac {R}{L}}{\frac {di}{dt}}+{\frac {1}{LC}}i=0$
The equation above can be written as below
    ${\frac {d^{2}i}{dt^{2}}}=-2\alpha {\frac {di}{dt}}-\beta i$
With
    $\alpha ={\frac {R}{2L}}=\beta \gamma$
    $\beta ={\frac {1}{LC}}={\frac {1}{T}}$
    $T=LC$
    $\gamma =RC$
Roots of 2nd ordered differential equation above
* $\alpha =\beta$
    $i(t)=Ae^{-\alpha t}$
* $\alpha >\beta$
    $i(t)=Ae^{(-\alpha \pm \lambda )t}$
* $\alpha <\beta$
    $i(t)=Ae^{(-\alpha \pm j\omega )t}=A(\alpha )\sin \omega t$

### Resonance Response

The total impedance of the circuit
    $Z=Z_{R}+Z_{L}+Z_{C}=R+0=R$
    $i={\frac {V}{R}}$
    $Z_{L}=Z_{C}$
    $j\omega L={\frac {1}{j\omega C}}$
    $\omega _{o}=\pm j{\sqrt {\frac {1}{T}}}$
    $T=LC$
    At $\omega _{o}=\pm j{\sqrt {\frac {1}{T}}}$ the total impedance of the circuit is Z = R . Therefore, current is equal to $i={\frac {V}{R}}$
    At $\omega =0.Z_{C}=oo$ , Capacitor opens circuit . Therefore, current is equal to zero
    At $\omega =oo.Z_{L}=oo$ , Inductor opens circuit . Therefore, current is equal to zero
# Practical Electronics/Resistors/Parallel Proof

This page presents a proof that the resistance of a parallel network, R$_{tot}$ of n resistors is the reciprocal of the sum of the reciprocals of the individual resistors:
First, consider that a current into (and out of) the whole network, i$_{tot}$, must be equal to the sum of the currents in each resistor (Kirchhoff's Current Law).
       $i_{tot}=\sum \limits _{k=1}^{n}{i_{k}},$
where i$_k$ is the current in the kth resistor in the network. Now, from Ohm's Law, we can write:
       ${{v_{tot}} \over {R_{tot}}}=\sum \limits _{k=1}^{n}{{v_{k}} \over {R_{k}}},$
where:
* v$_{tot}$ is the voltage across the entire network
* R$_{tot}$ is the resistance of the entire network
* v$_k$ is the voltage across the kth resistor in the network
* R$_k$ is the resistance of the kth resistor in the network
Since we know that the voltage across each resistor is the same (a trivial case of Kirchhoff's Voltage Law), we can say
       ${{v} \over {R_{tot}}}=\sum \limits _{k=1}^{n}{{v} \over {R_{k}}},$
where v is the voltage across the network. Dividing through by v gives us our final answer:
       ${{1} \over {R_{tot}}}=\sum \limits _{k=1}^{n}{{1} \over {R_{k}}}.$
This is also sometimes equivalently written as:
       $R_{tot}={1 \over {\sum \limits _{k=1}^{n}{1 \over {R_{k}}}}}$
This is a vital result and should be remembered. Notice that the proof for series networks is essentially the same, but uses KCL first and KVL second.
Other interesting points are that this result describes behaviour of series capacitive networks and parallel inductive networks.
# Practical Electronics/Signals/Basics

An electrical signal can refer to any quantity that veries with time. Usually, this quantity is voltage.
# Practical Electronics/Series RC
## Series RC

A circuit of two components R and C connected in series

## Circuit analysis
### Circuit's Impedance

In Rectangular coordinate
* $Z=Z_{R}+Z_{C}$
    $Z=R+{\frac {1}{j\omega C}}={\frac {1}{j\omega C}}(1+j\omega T)$
    $T=RC$
In Polar coordinate
* $Z=Z_{R}+Z_{C}$
    $Z=R\angle 0+{\frac {1}{\omega C}}\angle -90=|Z|\angle \theta ={\sqrt {R^{2}+({\frac {1}{\omega C}})^{2}}}\angle Tan^{-}1{\frac {1}{\omega RC}}$
    $Tan\theta ={\frac {1}{\omega RC}}={\frac {1}{2\pi fRC}}={\frac {t}{2\pi RC}}$
The value of $\theta ,\omega ,f$ depend on the value of R and C . Therefore, when the value of R or C changed the value of Phase angle difference between Current and Voltage, Frequency, and Angular of Frequency also change
    $\omega ={\frac {1}{Tan\theta RC}}$
    $f={\frac {1}{2\pi Tan\theta RC}}$
    $t=2\pi Tan\theta RC$

### Circuit's Response

Natural Response of the cicuit can be obtained by setting the differential equation of the circuit to zero
    $L{\frac {di}{dt}}+iR=0$
    ${\frac {di}{dt}}=-{\frac {R}{L}}i$
    $\int {\frac {di}{i}}=-{\frac {R}{L}}\int dt$
    $Lni=-({\frac {R}{L}})t+e^{c}$
    $i=Ae^{-}({\frac {R}{L}})t$
    $i=Ae^{-}({\frac {t}{T}})$
    $A=e^{c}={\frac {V}{R}}$
    $T=RC$
The natural response of the circuit is an exponential decrease
# Practical Electronics/Sin Wave Oscillator

With an LC series
    $L{\frac {dI}{dt}}+{\frac {1}{C}}\int Idt=0$
    ${\frac {d^{2}I}{dt}}+{\frac {1}{LC}}I=0$
    ${\frac {d^{2}I}{dt}}+{\frac {1}{LC}}=0$
    ${\frac {d^{2}I}{dt}}=-{\frac {1}{T}}$
    $I=Ae^{\pm j\omega t}=A\sin \omega t$
The reponse of an LC series is a Sinusoidal Wave or LC series can be used to produce Sin Wave Oscillator
# Practical Electronics/Series LC
## Circuit response
### At equilibrium

When circuit is at equilibrium, the total voltage of the circuit is zero
    $v_{L}+V_{C}=0$
    $L{\frac {di}{dt}}+{\frac {1}{C}}\int idt=0$
    ${\frac {d^{2}i}{dt^{2}}}+{\frac {1}{LC}}=0$
    ${\frac {d^{2}i}{dt^{2}}}=-{\frac {1}{T}}$
    $i=Ae^{\pm j\omega t}=A\sin \omega t$
    $\omega ={\sqrt {\frac {1}{T}}}$
    $T=LC$

### At resonance

When circuit is a resonance , the total impedance of the circuit is zero
    $Z_{L}+Z_{C}=0$
       $Z_{C}=-Z_{L}$
       ${\frac {1}{\omega C}}=-\omega L$
       $\omega _{o}=\pm j{\sqrt {\frac {1}{T}}}$
       $T=LC$
    $v_{L}+v_{C}=0$
       $v_{C}=-v_{L}$
       $v(\theta )=A\sin(\omega _{o}t+2\pi )-A\sin(\omega _{o}t-2\pi )$
# Practical Electronics/Resistors/Series Proof

This page presents a proof that the resistance of a series network, R$_{tot}$ of n resistors is the sum of the resistance of each resistor in the network:
First, consider that a voltage across the whole network must be equal to the sum of the voltages across each resistor (Kirchhoff's Voltage Law).
       $v_{tot}=\sum \limits _{k=1}^{n}{v_{k}},$
where v$_k$ is the voltage across the kth resistor in the network. Now, from Ohm's Law, we can write:
       $i_{tot}R_{tot}=\sum \limits _{k=1}^{n}{i_{k}R_{k}},$
where:
* i$_{tot}$ is the current through the entire network
* R$_{tot}$ is the resistance of the entire network
* i$_k$ is the current in the kth resistor in the network
* R$_k$ is the resistance of the kth resistor in the network
Since from Kirchhoff's Current Law we know that the current in each resistor is the same, we can write
       $iR_{tot}=i\sum \limits _{k=1}^{n}{R_{k}},$
where i is the current through the network. Dividing through by i gives us our final answer:
       $R_{tot}=\sum \limits _{k=1}^{n}{R_{k}}$
This is a vital result and should be remembered. Notice that the proof for parallel networks is essentially the same, but uses KCL first and KVL second.
Other interesting points are that this result describes behaviour of parallel capacitive networks and series inductive networks.
# Question Writer Manual/Extras/Language Selector
## Language Selector

You can change the language of Question Writer by using the language selector. You select the language you want to use in the Language menu that is visible before you've opened or created any quizzes in the interface.
After you've changed the language, you need to restart the application for the change to kick in. The languages currently supported are:
* English
* Danish
* French
* German
* Icelandic
* Italian
* Korean
* Portuguese
* Spanish
* Swedish
* Japanese
# Question Writer Manual/Frequently Asked Questions/CD

* Can I save and publish the quiz on a CD?
Yes, you can easily save the .qwz files to a CD eg for back up, and you can also save your published .html and .swf files to CD. Just follow your normal procedure for saving files to CD. Users can then access the quiz from the CD via their browser.
You can also first convert the .swf files to a .exe file using software known as a Flash Projector and then save them to CD. This way Windows users will be able to access the quiz even if they do not have flash installed on their pc. You can go online and easily find Flash Projector software to download free of charge.
See the chapter Save and Publish for more information on saving and publishing your quiz.
# Question Writer Manual/Frequently Asked Questions/Arabic

* Does Question Writer 3 support "right to left" script?
Unfortunately, at present Question Writer 3 does not support right to left text.
Even if a right to left ISO embedded font is used, any right to left text that is entered will be flipped over when the quiz is viewed.
It is possible, if you have time and determination, to input your right to left text with all words and letters in reverse order.
The example given below shows part of the front page of the Italian quiz sample with arabic script. The resulting quiz shows the script characters in their standalone form, which makes reading much slower. If you attempt this workaround, you will also have to make sure that you do not use any question types which require a written answer (fill in the blank or essay types).
# Question Writer Manual/Frequently Asked Questions/Email Results

* Why am I not receiving E-mail results?
There can be a number of reasons why you might not be receiving the results by e-mail.

### 1. Quiz Set Up

Check you have ticked the box in Send Results over the Internet and given a correct email address for the results to be sent to.
Important Note: If you are publishing your quiz to the Question Writer Tracker service, this setting will be ignored and the e-mail address associated with your Question Writer Tracker account will be used instead.
You should make sure that the url for the results server and back up results server are correct. If you are not using your own custom server, the address for the server should be - http://www.questionwritertracker.com/collator/results.php?email= and for the back up server - http://www.xquestion.com/results/resultsqw3.php?email=
Note: Don't add your e-mail address to the end of these links. That will be done automatically.
You should then choose the Publish to the Web option in Publish menu and upload all (at least 3) files to your website. See Create a Web Page for more information on uploading files to your web page.

### 2. Quiz Taker Set Up

The quiz taker needs to have internet access to send the results through to our server. Check they can access these websites to ensure they have access to the main server and backup server. http://www.questionwritertracker.com
http://www.xquestion.com
The quiz taker should access the quiz through the webpage (index.html) for results to be sent by e-mail. See Create a Web Page for an idea of how you can do this.

### 3. E-mail Box Set Up

We send a lot of e-mails with results and some mail programs get confused and think these e-mails are spam. Check your spam box and any e-mail filter rules to ensure that the results are not being sent to spam. In some instances, your e-mail service provider may not forward the e-mails to you if it identifies them as spam. If this happens we recommend you alert your e-mail service provider, but often the fastest way to correct this is to set up another e-mail box to receive the e-mail. Many people have had good success with Gmail. http://www.gmail.com

### 4. Set up your results server account

You might find it easier to view your results online with the results server . You can register to view your results online. You may also subscribe/unsubscribe from the results by email service here.
There is more information about the results service in the chapter on Results.