I have a file, and several processes which can operate on it. For simplicity let us assume that each process runs the same script: with open(&quot;file.txt&quot;, &quot;r+&quot;) as file:     data = file.read()     data = data + &quot;Hello\n&quot;     file.seek(0)     file.write(data)  I assume that such a way of file access allows several processes to modify the same file, what results in improper writing (for instance, three processes could get &quot;HeHello\nHello\nllo&quot; as a result). Is there any way to forbid access to the file for some time and still be able to read and write from there from the current process?
What is the most elegant way to solve this:   open a file for reading, but only if it is not already opened for writing open a file for writing, but only if it is not already opened for reading or writing   The built-in functions work like this  &gt;&gt;&gt; path = r"c:\scr.txt" &gt;&gt;&gt; file1 = open(path, "w") &gt;&gt;&gt; print file1 &lt;open file 'c:\scr.txt', mode 'w' at 0x019F88D8&gt; &gt;&gt;&gt; file2 = open(path, "w") &gt;&gt;&gt; print file2 &lt;open file 'c:\scr.txt', mode 'w' at 0x02332188&gt; &gt;&gt;&gt; file1.write("111") &gt;&gt;&gt; file2.write("222") &gt;&gt;&gt; file1.close()   scr.txt now contains '111'.  &gt;&gt;&gt; file2.close()   scr.txt was overwritten and now contains '222' (on Windows, Python 2.4).  The solution should work inside the same process (like in the example above) as well as when another process has opened the file. It is preferred, if a crashing program will not keep the lock open.
Will wolves attack Ocelots? Will wolves attack and kill ocelots in Minecraft? I know they kill sheep. I just don't want my cats being eaten. How do I find out word count in pages 5.2.2 I often write short articles and am limited to 100 words per document.   Can I find word counts in pages 5.2.2? Using the uncertainty principle to estimate the ground state energy of hydrogen I have been reading through this  of the ground state energy of hydrogen  and others like it. In this one it says it is using the uncertainty principal but then proceeded to use the following: $$pr=\hbar$$ But why is it not using: $$pr=\frac{\hbar}{2}$$ which is more in line with the uncertainty principle and what comes earlier in the derivation. java.lang.NumberFormatException: Invalid int: "" Layers with different directional drop shadows in Photoshop I am wondering how to have 2 different directional drop shadows in the one file with Photoshop. e.g. 2 different type layers — one has a drop shadow at 90 degrees, the other at -45 degrees.  Currently it seems Photoshop only lets me have 1 universal direction for the whole file, which I find really pointless.   I know how to apply different drop shadows and merge down layers to achieve the same thing, but its tedious and not exactly streamlined for making future changes to that layer.  How is this achieved? If $a$ and $b$ are relatively prime, prove that $a + 2b$ and $2a+b$ are also relatively prime or have a $\gcd$ of $3$.  I'm very new to number theory so please don't assume I am familiar with some of the terminology. I'm not a git master, but I have been working with it for some time now, with several different projects.  In each project, I always git clone [repository] and from that point, can always git pull, so long as I don't have outstanding changes, of course.  Recently, I had to revert to a previous branch, and did so with git checkout 4f82a29.  When I was again ready to pull, I found that I had to set my branch back to master.  Now, I can not pull using a straight git pull but instead, have to specify git pull origin master, which is annoying, and indicates to me that I don't fully understand what is going on.  What has changed which does not allow me to do a straight git pull without specifying origin master, and how to I change it back?  UPDATE:  -bash-3.1$ cat config [core]     repositoryformatversion = 0     filemode = true     bare = false     logallrefupdates = true [branch "master"] [remote "origin"]     url = git@github.com:user/project.git     fetch = refs/heads/*:refs/remotes/origin/*   UPDATE 2: To be clear, I understand that my original method may have been incorrect, but I need to fix this repo so that I can simply use git pull again.  Currently, git pull results in:  -bash-3.1$ git pull You asked me to pull without telling me which branch you want to merge with, and 'branch.master.merge' in your configuration file does not tell me either.  Please name which branch you want to merge on the command line and try again (e.g. 'git pull  '). See git-pull(1) for details on the refspec.  If you often merge with the same branch, you may want to configure the following variables in your configuration file:      branch.master.remote =      branch.master.merge =      remote..url =      remote..fetch =   See git-config(1) for details.   I can tell git pull which branch to merge, and it works correctly, but git pull does not work as it did originally before my git checkout. Am I allowed to make a Stack Overflow clone? SO is not Open-Source, but I like the whole idea of Stack Overflow :   Giving bounties for Questions Up/Downvoting Questions The Badges The intelligent use of Ajax-Technologies Highly Rated users have administrative powers Reputation system Editing posts like a wiki   So I would like to program a (what is it called) Q&amp;A site / board / wiki system. Am I allowed to? What happens when you put a Portable Hole inside a Bag of Holding while on the Astral plane? What would happen if someone were to place a Portable Hole within a Bag of Holding while being within the Astral Plane? Would it be the reverse effect? How can I assign a Func conditionally between lambdas using the conditional ternary operator? Arbitrary precision spline interpolation I always thought of current as the time derivative of charge, $\frac{dq}{dt}$. However, I found out recently that it is the ampere that is the base unit and not the coulomb. Why is this? It seems to me that charge can exist without current, but current cannot exist without charge. So the logical choice for a base unit would be the coulomb. Right? Calculate total sum of all numbers in c:forEach loop I have a Java bean like this:  class Person {   int age;   String name; }   I'd like to iterate over a collection of these beans in a JSP, showing each person in a HTML table row, and in the last row of the table I'd like to show the total of all the ages.  The code to generate the table rows will look something like this:  &lt;c:forEach var="person" items="${personList}"&gt;   &lt;tr&gt;&lt;td&gt;${person.name}&lt;td&gt;&lt;td&gt;${person.age}&lt;/td&gt;&lt;/tr&gt; &lt;/c:forEach&gt;   However, I'm struggling to find a way to calculate the age total that will be shown in the final row without resorting to scriptlet code, any suggestions? I've just installed Ubuntu 16.04 LTS on dual boot. I've looked for many solutions and tried them all but Chrome never starts; the logo appears on the left but no window opens.  I downloaded the deb file on google chrome website and installed it through Ubuntu Software, but it doesn't start.   I have tried installing it through the command line with   sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb sudo apt-get install -f   I have checked with uname -a and my system is 64 bit. I have also tried gdebi with the same result.   My repository universe is up to date.  I only have one display in settings>displays> so I can't turn off built-in display nor check the mirror display (I read it could be the problem as I also have a graphic card but it seems it is not in my case).  Here is what I get in the command line when I try to run Chrome from it ( the message is the same, whatever the method I used to install Chrome):  ~$ google-chrome [11831:11831:1122/114854.195473:ERROR:process_singleton_posix.cc(433)] readlink failed: Permission denied (13) [11831:11831:1122/114854.195493:ERROR:process_singleton_posix.cc(256)] readlink(/home/basil/.config/google-chrome/SingletonLock) failed: Permission denied (13) [11831:11831:1122/114854.195508:ERROR:process_singleton_posix.cc(256)] readlink(/home/basil/.config/google-chrome/SingletonLock) failed: Permission denied (13) [11831:11831:1122/114854.195515:ERROR:process_singleton_posix.cc(280)] Failed to create /home/basil/.config/google-chrome/SingletonLock: Permission denied (13) [11831:11831:1122/114854.195538:ERROR:process_singleton_posix.cc(433)] readlink failed: Permission denied (13) [11831:11831:1122/114854.195564:ERROR:process_singleton_posix.cc(256)] readlink(/home/basil/.config/google-chrome/SingletonLock) failed: Permission denied (13) [11831:11831:1122/114854.195622:ERROR:chrome_browser_main.cc(1498)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption. [11831:11868:1122/114854.209297:ERROR:browser_gpu_channel_host_factory.cc(108)] Failed to launch GPU process.   Any new approach will be much appreciated Self-deletion and un-deletion without any changes should reinstate the original close/delete votes Applied boolean modifier leaving shading artifacts with flat shading I tried to manipulate a cube with the Boolean modifier. I tried to cut out an edge of the cube with a cylinder. Also, the shading result looks awful in FLAT SHADING mode, so I turned on SMOOTH SHADING.   Has anyone an idea how to achieve a better result. (I also cut out a Sphere first, this made the result less awful).   I used Blender Internal and rendered with smooth shading for smoothness.  Using flat shading looks okay, except the "round" cutouts :/  Face normals are okay.  First image is smooth shading.    EDIT: User Pisurquatre suggested the EdgeSplit modifier, works perfect to me (Maybe a little tweaking here and there): I have an input type="image". This acts like the cell notes in Microsoft Excel. If someone enters a number into the text box that this input-image is paired with, I setup an event handler for the input-image. Then when the user clicks the image, they get a little popup to add some notes to the data.  My problem is that when a user enters a zero into the text box, I need to disable the input-image's event handler. I have tried the following, but to no avail.  $('#myimage').click(function { return false; }); Deriving curvature formula How do you derive the formula for unsigned curvature of a curve $\gamma (t) = (x(t), y(t)$ which is not necessarily parameterised by arc-length.   The formula given is $$|\kappa (t)| = \left|\frac{x'' y' - y'' x'}{((x')^2 + (y')^2)^{3/2}}\right|$$  All the definitions of curvature in my notes give it in terms for an arc-length parameterisation $T'(s) = \kappa(s) N(s)$. This is apparently meant to be 'easily derivable', am I missing something? match first column of file a with paragraphs of file b I have 2 files. The first, fileA looks like  TCONS_00000066  XLOC_000030     -       u       q1:XLOC_000030|TCONS_00000066|0|0.000000|0.000000|0.000000|0.000000|- TCONS_00000130  XLOC_000057     -       u       q1:XLOC_000057|TCONS_00000130|0|0.000000|0.000000|0.000000|0.000000|- TCONS_00000395  XLOC_000206     -       u       q1:XLOC_000204|TCONS_00000393|0|0.000000|0.000000|0.000000|0.000000|-   FileB looks like:  &gt;TCONS_00000001 gene=XLOC_000001 AGATGAGCTGGTGGGGATGCTCTAAGAGAACGAGAGAAGCACAGAGCAGATAAACCACACCCACAGGCAC CACCGTCCTTGTTGGTAATGAAGAAGACGAGACGACGACTTCCCCACTAGGAAACACGACGGAGGCGGAG ATGATCGACGGCGGAGAGAGCTACAGAAACATCGATGCCTCCTGTCCAATCCCCCCATCCCATTCGGTAG TTGGATTGAAGACTACCGAATAAGAGAAGCAGGCAGGCAGACAAACCCTTGAACCAAGGAGTCCTCGCTG AGGAAGCTTTGGATCCACGACGCAGCTATGGCCTCCCCGCCCACCAGGCCGCCAGCCACAACCAGCTGAC TAGGTCGCATGCATCATCAGATTTCAATCTCCCTTCGTTCCCTGTCCCTAATCCAATACCAATAGGGAGC AATCAGCTGCTCCTCGACGGCGAGGGAGATGTCGTCGGCCGCGGGCCAAGACAACGGAGATACCGCTGGG GACTACATCAAGTGGATGTGCGGCGCCGGTGGCCGTGCGGGCGGCGCCATGGCCAACCTCCAGCGCGGCG TTGGCTCCCTCGTCCGTGACATTGGCGACCCCTGCCTCAACCCATCCCCCGTTAAGGGGAGCAAAATGCT CAAACCGGAAAAATGGCACACATGTTTTGATAATGATGGAAAGGTCATAGGTTTCCGTAAAGCCCTAAAA TTCATTGTCTTAGGGGGTGTGGATCCCACTATTCGAGCTGAAGTTTGGGAATTTCTTCTTGGCTGCTATG CCTTGAGTAGTACCTCAGAGTATAGGAGGAAACTAAGAGCTGTTAGAAGGGAAAAATATCAAATTTTAGT TAGACAGTGCCAGAGCATGCACCCAAGCATTGGTACAGGTGAGCTTGCTTACGCTGTTGGATCAAAGCTA   Now, fileA contains selected transcript numbers in the first column and fileB contains sequences of all transcripts. I want to scan fileB for the first column of fileA and print the trailing sequences of matching transcripts along with the transcript number. A company is any form of business whether it is small or large. Generally the term &quot;company&quot; indicates a particular kind of business dealing in a specific product. An organisation is the larger form and generally comprises of a number of companies.  Simply, a company is an organization, but an organization is not just a company. An industry is the combination of companies in same line of business. Firm, corporation and business  are synonyms of &quot;company&quot;. An Agency is a particular kind of company, which serves as an intermediary between clients (other companies or individuals).  Is this correct?