In python, how could i split a file into smaller chunks efficiently? for example, I have a file contains 140 lines. I want to split the file into file1.txt, file2.txt, file3.txt. file1 has 50 lines, file2 has 50 lines and file3 has the rest 40 lines.
I have a huge text file (~1GB) and sadly the text editor I use won't read such a large file.  However, if I can just split it into two or three parts I'll be fine, so, as an exercise I wanted to write a program in python to do it.    What I think I want the program to do is to find the size of a file, divide that number into parts, and for each part, read up to that point in chunks, writing to a filename.nnn output file, then read up-to the next line-break and write that, then close the output file, etc.  Obviously the last output file just copies to the end of the input file.  Can you help me with the key filesystem related parts: filesize, reading and writing in chunks and reading to a line-break?  I'll be writing this code test-first, so there's no need to give me a complete answer, unless its a one-liner ;-)
Is there a difference between "" and {} in BibTeX? This seems like a pretty softball question, but I always have a hard time looking up this function because there seem there are so many variations regarding the referencing of char and tchar. Evaluating $\prod_{n=1}^{\infty}\left(1+\frac{1}{2^n}\right)$ Let $p$,$\ q$ be prime numbers and $n\in \mathbb{N}$ such that $p \nmid n-1$. If $p \mid n^q-1$, then $q \mid p-1$. Deciding whether $2^{\sqrt2}$ is irrational/transcendental Is $2^\sqrt{2}$ irrational? Is it transcendental? What's the single-word for "left or right handed"? 'Male'/'female' is to 'gender' as 'left-handed'/'right-handed 'is to...?  Is there a word to describe this? For example, if I ask a guy     What's your ____?   It should mean I'm asking whether he's left or right-handed.  Another example could be     Our designs are not biased  against your ____.   Basically, I'm looking for something that means the state of being left- or right-handed which could be used analogously as gender.  EDIT: Sorry for the delay in the edit, but I was tied up. There are some points I'd like to clarify:   I'm not looking for a way to paraphrase my questions. I'm looking for a single word. I know people normally ask something along the lines of "Are you left-handed or not?" People also ask "Are you afraid of the dark?" instead of "Are you scotophobiac?". The word for it,  still exists, right? It has been pointed out that I should go with Our designs are not biased against left-handed people as that is what I mean. But that is not necessarily what I mean.    For example, let's say there is a washbasin with the tap on the right. Clearly, it's biased against lefties. Sometimes, you come across a washbasin with a tap on the left. (The logic being: you use your left hand to turn the tap as your right one's dirty). But, your right hand might not always be dirty, in which case, it's biased against righties.  A washbasin with the tap on the center is, then, handedness-blind or chirality-blind, if you will. (I foresee that some would dwell on Our designs are symmetrical. Please don't.)  I'm looking for a term that would be applicable here, as well as in the 1st example.  My favorite so far is chirality, suggested by Dan Bron in a comment (with 25 upvotes!) But, I'm reluctant to use it because there's no hard proof it's used in that sense  If we are talking about male-female, gender works perfectly. What's your gender? and Our designs aren't biased against your gender. , both work perfectly here.  Sorry for the late edit again. If the consensus is that I rollback, I will. Let me know in the comments. Let $K/F$ be a finite field extension and suppose that $F$ is infinite. Is it possible to have a nonzero polynomial $p \in K[x_1,...,x_n]$ that vanishes in $F^n$? Is there a complete list of these? I've seen lots of Q&amp;A about "What does x icon mean" but it would be really useful if there were a complete list for reference! Recommended way to initialize srand? I need a 'good' way to initialize the pseudo-random number generator in C++. I've found  that states:     In order to generate random-like   numbers, srand is usually initialized   to some distinctive value, like those   related with the execution time. For   example, the value returned by the   function time (declared in header   ctime) is different each second, which   is distinctive enough for most   randoming needs.   Unixtime isn't distinctive enough for my application. What's a better way to initialize this? Bonus points if it's portable, but the code will primarily be running on Linux hosts.  I was thinking of doing some pid/unixtime math to get an int, or possibly reading data from /dev/urandom.  Thanks!  EDIT  Yes, I am actually starting my application multiple times a second and I've run into collisions. A proof for the inequality $\sum_{i=0}^{t-2}{\frac{1}{t+3i}} \leq \frac{1}{2} $ for all $t \geq 2$ I'm struggling with proving the following inequality: $$\sum_{i=0}^{t-2}{\frac{1}{t+3i}} \leq \frac{1}{2}$$  for all $t \geq 2$. I think it is monotonic non-increasing in $t$, which would suffice.  Thanks in advance! biblatex: Tighter integration of \textcite "in the flow of text" This question led to a new feature in a package:      Many biblatex citation styles feature the \textcite command which is "intended for use in the flow of text, replacing the subject of a sentence" (manual, section 3.6.2). At the moment, this works well for citations of single works -- e.g. (assuming the authoryear style), one may write in the source  The reference work is \textcite{knuth:ct:a}.   which will be typeset as     The reference work is Knuth (1984).   Citing multiple works, on the other hand, is somewhat tedious. If one simply writes (1):  Important works are \textcite{knuth:ct:a,knuth:ct:b,markey}.   the output is rather a list than a correct sentence (2):     Important works are Knuth (1984); Knuth (1986); Markey (2005).   One has to write (3):  Important works are \textcite{knuth:ct:a}, \textcite{knuth:ct:b}, and \textcite{markey}.   to get (4):     Important works are Knuth (1984), Knuth (1986), and Markey (2005).   Can \textcite be modified so that input (1) will yield output (4), hereby achieving a tighter integration "in the flow of text"?  \documentclass{article}  \usepackage[style=authoryear]{biblatex}  \addbibresource{biblatex-examples.bib}  \begin{document}  This is how \texttt{\textbackslash textcite} currently works:\\ Important works are \textcite{knuth:ct:a,knuth:ct:b,markey}.  \bigskip  But I'd like \texttt{\textbackslash textcite} to output the following:\\ Important works are \textcite{knuth:ct:a}, \textcite{knuth:ct:b}, and \textcite{markey}.  \printbibliography  \end{document} Eevee - Light inside a bulb lamp not passing through glass Using Eevee, I'm trying to simulate a light bulb. I have a sphere with glass material and inside it, I have a Point light. But the light is not passing through the glass:  However, if I disable the sphere object, the light is working:   How to make the light inside a bulb lamp pass through glass (using Eevee)? Here my test project: You can't see the question owner's special color Is "National Socialism" always capitalized? So, I'm writing a paper on the rise of communism in China. At one point I write the following:     "Today, it is well known that communism is responsible for more deaths than even national socialism."   Then, Word corrects it by capitalizing "National Socialism."   Is it always meant to be capitalized? I am simply referencing the ideology, not necessarily the Third Reich. Word didn't bother to correct "communism." I suppose since there was only one instance of Nazism (on a national scale at least) it could be considered a proper noun. Probability of an even number of sixes We throw a fair die $n$ times, show that the probability that there are an even number of sixes is $\frac{1}{2}[1+(\frac{2}{3})^n]$. For the purpose of this question, 0 is even.   I tried doing this problem with induction, but I have problem with induction so I was wondering if my solution was correct:   The base case: For $n=0$, our formula gives us $\frac{1}{2}[1+(\frac{2}{3})^0] =1$. This is true, because if we throw the die zero times, we always get zero sixes.  Suppose it's true for $n=k$. Then the odds of an even number of sixes is $\frac{1}{2}[1+(\frac{2}{3})^n]$, and thus the odds of an odd number of sixes is $1 - \frac{1}{2}[1+(\frac{2}{3})^n]$.    For $n=k+1$, there are two ways the number of sixes are even:  a. The number of sixes for $n=k$ was even, and we do not throw a six for $n=k+1$: $ \frac{5}{6} \cdot  \frac{1}{2}[1+(\frac{2}{3})^n]$  b. The number of sixes for $n=k$ was odd, and we throw a six for $n=k+1$: $\frac{1}{6}(1 - \frac{1}{2}[1+(\frac{2}{3})^n])$  So the probability $p$ for an even number of sixes at $n=k+1$ is $ \frac{5}{6} \cdot  \frac{1}{2}[1+(\frac{2}{3})^n] + \frac{1}{6}(1 - \frac{1}{2}[1+(\frac{2}{3})^n])$  I have two questions   How do I get from $ \frac{5}{6} \cdot  \frac{1}{2}[1+(\frac{2}{3})^n] + \frac{1}{6}(1 - \frac{1}{2}[1+(\frac{2}{3})^n])$ to $\frac{1}{2}[1+(\frac{2}{3})^n]$? I seem to have done something wrong, I can't get the algebra correct, I get $p = \frac{1}{3}[1+(\frac{2}{3})^n] + \dfrac{1}{6}$ Other than that, is my use of induction correct? Is it rigorous enough to prove the formula? What's wrong with this argument that $[0,1]$ is countable? Natural examples of deformation retracts that are not strong deformation retracts The question  asks for examples of deformation retracts which are not strong deformation retracts. A comment is given refering the asker to Exercise 0.6 in Hatcher. (The description of this space also appears in , which is about this very same exercise.)  This space, however, seems to be constructed specifically for this purpose.     Are there any naturally occurring (by which I mean not constructed specifically for this purpose, arising in some other way) spaces that are deformation retracts but not strong deformation retracts?   The main reason for asking is that it doesn't seem very likely to me that one would stumble upon such a space at random, so I don't know what to watch out for. One can never be too careful. SELECT DISTINCT on multiple columns Supposing we have a table with four columns (a,b,c,d) of the same data type.  Is it possible to select all distinct values within the data in the columns and return them as a single column or do I have to create a function to achieve this? Automatically convert quotations in the form of "abc" to become ``abc" Why don't we include $\rho g h$ in a hydraulic jack below? Consider a hydraulic jack with massless pistons as follows.    The famous equation for this system is   $$ \frac{F_1}{A_1}=\frac{F_2}{A_2} $$  My question is why isn't the equation as follows?  $$ \frac{F_1}{A_1}=\frac{F_2}{A_2} + \rho g h $$  It is based on  my understanding that any points in the same horizontal line have the same pressure.  Could you spot my misconception?