for i in range(length):             template = &quot;Test_Template.docx&quot;         document = MailMerge(template)         document.merge(         **testlist[i]=format(T.entrys[i].get())**         )         document.write('test-output.docx')  The below piece of code actually replaces the value of the list item, but doesn't get supplied as kwarg to finish the job. #Where testlist is a list containing around 25 items. #Where T.entrys refers to a class object
56531
Does python have the ability to create dynamic keywords?  For example:  qset.filter(min_price__usd__range=(min_price, max_price))   I want to be able to change the usd part based on a selected currency.
18288
I have some kind of test data and want to create a unit test for each item. My first idea was to do it like this: import unittest  l = [[&quot;foo&quot;, &quot;a&quot;, &quot;a&quot;,], [&quot;bar&quot;, &quot;a&quot;, &quot;b&quot;], [&quot;lee&quot;, &quot;b&quot;, &quot;b&quot;]]  class TestSequence(unittest.TestCase):     def testsample(self):         for name, a,b in l:             print &quot;test&quot;, name             self.assertEqual(a,b)  if __name__ == '__main__':     unittest.main()  The downside of this is that it handles all data in one test. I would like to generate one test for each item on the fly. Any suggestions?
17166
I have a list of integers, List&lt;Integer&gt; and I'd like to convert all the integer objects into Strings, thus finishing up with a new List&lt;String&gt;.  Naturally, I could create a new List&lt;String&gt; and loop through the list calling String.valueOf() for each integer, but I was wondering if there was a better (read: more automatic) way of doing it?
66487
I am preparing some lecture notes/slides and would like to efficiently create two versions of the output: a complete version for myself, and a version for my students with certain text replaced with blanks or an empty box so that they can fill it in during lectures.  the \underline{\phantom{text}} command does the trick, but it would be time consuming to create a separate version of the document and insert this in all the relevant places.  How can one use macros to give us the ability to easily toggle between the teacher version (with full text) and student version (with blanks)?  I was going to post this as a question but then figured it out so thought I'd share it.
11412
Is there any easy LINQ expression to concatenate my entire List&lt;string&gt; collection items to a single string with a delimiter character?  What if the collection is of custom objects instead of string? Imagine I need to concatenate on object.Name.
56058
I've written a python script using arcpy which outputs a polygon feature class into a File Geodatabase.  I have added a function to export the attributes to a separate CSV file.  I am using the code which I have found in  which works perfectly.  However, that code exports every column in the feature class.  I only want to export the fields that do not have the following names: OBJECTID, Shape, or Shape_Length.  My CSV file generates successfully, and it correctly does not include the OBJECTID or Shape_Length fields.  However, the Shape field is written to the file.  An example value that is written to that field is:  &lt;geoprocessing describe geometry object object at 0x28CB90A0&gt;   I have added a line to print the field names as it iterates through them and surprisingly, Shape is not printed.  It's as if ArcGIS is hiding it or gives it a different name.  The code for my function is below:  def exportToTable():     """          Exports the final outputs to a CSV File.     """      # Create path to CSV File (note the varialbe outputPath is declared elsewhere).     CSVFile = outputPath+'\\FinalOutput.csv'     arcpy.AddMessage("Created CSV File: %s" %CSVFile)      # Get all fields in FinalOutput feature class and remove unwanted fields.     fields = arcpy.ListFields('FinalOutput')     for field in fields:         arcpy.AddMessage("Field.name is:"+field.name) #not printing 'Shape' field name         if field.name in (['OBJECTID', 'Shape', 'Shape_Length']):             fields.remove(field)      i = 1     f=open(CSVFile, 'w')     for field in fields:         #--write the wanted field names to the output file         if i &lt; len(fields):             f.write('%s,' % field.name)             i += 1         else:             f.write('%s\n' % field.name)      # Use a search cursor to iterate through the rows of the table and write them to the CSV file.     rows = arcpy.SearchCursor('FinalOutput')     for row in rows:         i = 1         for field in fields:             if i &lt; len(fields):                 f.write('%s,' % row.getValue(field.name))                 i += 1             else:                 f.write('%s\n' % row.getValue(field.name))     del rows     f.close()   Does anyone know what's going on here?    I modified my code to follow the advice of @sgrieve and it was still writing the Shape field.  If I add a line to print the field names as it iterates through them, it lists all the fields except the Shape field, yet it still writes to the CSV.  It also added the X and Y coordinates of the polygon as two new columns and the columns no longer aligned with the column names.  I've modified the line where @sgrieve declares the fields to be the following:   fields = [f.name for f in arcpy.ListFields('FinalCadastre') if f.type &lt;&gt; 'Geometry']   The new code works fine, but I'm still unsure what the problem was.  Does anyone know what was going on?  What's the deal with the Shape field?
65244
I have to regularly create 100+ text files from templates. I currently use an overly complicated shell script. I think there is a smarter way to handle this, but I don't know how.  I have a "database" :  # outputfile      template            data1   data2    data3 first.txt         $template_main      $text1  abcd     1234 second.txt        $template_main      $text2  efgh     5678 third.txt         $template_other     $text1  ij       90   And a configuration file :  template_main=main.txt template_other=other.txt text1=whatever text2=blah   The templates are text files with placeholders like %%data2%% (the placeholder form can be changed).  Does someone know a tool to automate this better than with a complicated shell script ?
13384
I'm trying to switch from enumitem lists to tasks lists, but the following, which works in an ordinary enumerate environment, generates a "Something's wrong--perhaps a missing \item" error in the tasks environment:  \documentclass{article} \usepackage{tasks} \newcommand{\itemexpansion}{\item test \item test \item test \item test} \newcommand{\taskexpansion}{\task test \task test \task test \task test}  \begin{document} % OK \begin{enumerate}     \itemexpansion \end{enumerate} % Error \begin{tasks}     \taskexpansion \end{tasks} \end{document}   I can tell that there's an expansion problem here, but that's about as far as my comprehension extends. It doesn't seem to match the situations warned about in the manual. Is there a workaround that will allow me to dump the results of a macro (the contents of which are gathered elsewhere) into a tasks environment?
8318
I have a list like so.  blue-image1.jpg, blue-image2.jpg, blue-image3.jpg red-image1.jpg, red-image2.jpg, red-image3.jpg   It's was originally a csv format but I added newlines because they needed a prefix at first. Now I need to put them together again so it becomes like this.  blue-image1.jpg,blue-image2.jpg,blue-image3.jpg red-image1.jpg,red-image2.jpg,red-image3.jpg   I tried cat list.txt | tr ',\n' ',' and cat list.txt | sed 's/,\n/,/g'  but neither seem to work properly.
120657
Suppose, I have the following code:  \documentclass{article} \begin{document} We have totally 7 columns, describing the user: \begin{enumerate} \item ID --- users.name \item Forename --- users\_profiles.first\_name \item Surname --- users\_profiles.last\_name \item Email --- users.mail \item Primary Service --- services.name \item Start date --- FROM\_UNIXTIME(users.created) \item Employment Status --- users\_profiles.employment\_status \end{enumerate} \end{document}   Producing this document:    Is it possible to set the value 7 automatically, depending upon number of elements in the list? The problem is, that it resides before the list.
960
See code:   var file1 = "50.xsl"; var file2 = "30.doc"; getFileExtension(file1); //returns xsl getFileExtension(file2); //returns doc  function getFileExtension(filename) {     /*TODO*/ }
30569
I'm a beginner in LaTeX, and I was trying to edit a template to make my Resume. I'm using  template, as present in .    In this, I need to make a bulleted list of a few entries in 2 columns. It appears like:    exactly the way I want. But it doesn't match the style of rest of the resume. I have used    \begin{multicols}{2}     \begin{itemize}         \item item 1         \item item 2         \item item 3         \item item 4         \item item 5         \item item 6     \end{itemize} \end{multicols}   to achieve the above. How do I ensure the template font size/style applies to the above entries?
28318
I'm trying to format numbers. Examples:  1     =&gt; 1 12    =&gt; 12 123   =&gt; 123 1234  =&gt; 1,234 12345 =&gt; 12,345   It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.  Edit: If you've a generic Python way to do this, I'm happy adding a formatted field in my model.
91211
I am currently writing my thesis and need to include a bunch of email conversions. I am using classicthesis. I wonder, how you would format stacked conversions. Moreover, how would you deal with the email header, signatures and line breaks: why do I need to add \\ all the time? This is the configuration I am currently experimenting with:  \documentclass[ oneside, openright, titlepage, dottedtoc, numbers=noenddot, headinclude, footinclude=true, cleardoublepage=empty, abstractoff, BCOR=5mm, paper=a4, fontsize=11pt, ngerman, american ] {scrreprt}  \PassOptionsToPackage{utf8}{inputenc} \usepackage{inputenc} \usepackage{blindtext}  \usepackage{framed}  % Vertical line that highlights quotations in an email. % Use \begin{leftbar} and \end{leftbar} environment. % Width of the line = 0.4pt % Space between the line and the text = 10pt % Requires \usepackage{framed} \renewenvironment{leftbar}{%   \def\FrameCommand{\vrule width 0.4pt \hspace{10pt}}%   \MakeFramed {\advance\hsize-\width \FrameRestore}}% {\endMakeFramed}  \usepackage{nicefrac} \usepackage[english]{babel} \usepackage[pdfspacing]{classicthesis}  \begin{document} \selectlanguage{ngerman} % american ngerman % Disable paragraph indentation. \setlength{\parindent}{0pt}     \begin{verbatim} From: john.doe@yahoo.com Subject: Your inquiry from 20042012 Date: Thu, 3 May 2012 11:34:54 +0200 To: Jane Doe &lt;jane.doe@hotmail.com&gt; \end{verbatim}  Jane Doe wrote: \begin{leftbar} \begin{leftbar} \begin{leftbar} \begin{leftbar} There are a couple of questions I like to ask. Please forward them if you cannot do so. \end{leftbar} I hope I can answer them after holidays. \end{leftbar} I am back from holidays now and will look through your questionaire the next days. \end{leftbar} Thank you, Mr. Doe - I am awaiting your answers. \end{leftbar}  Dear Mrs. Doe,\\ \ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut molestie placerat pharetra. In quam leo, tincidunt ut consequat eget, malesuada sit amet urna. Morbi et interdum arcu. Nullam nisi nunc, ullamcorper vitae pulvinar eu, suscipit ut augue.\\ \ Donec risus mi, accumsan ac interdum id, molestie sed mauris. Suspendisse porttitor luctus justo in ullamcorper. Proin in neque magna. Mauris quis arcu eget enim mattis pharetra vitae a dolor. Nam aliquam consectetur mollis. Ut at sem quis dolor faucibus fringilla. Quisque cursus vehicula odio, vitae placerat ipsum dapibus id.\\ \ Best regards\\ John Doe\\ \ (See attached file: Questions\_Doe.doc)  \begin{verbatim} _______________________________________________________ Administration New York John Doe Mainstr. 3 11111 New York  T:        (011) 212-4301 F:            (011) 212-954301 M:         john.doe@yahoo.com \end{verbatim}  \begin{leftbar} My question I looking forward to reading the answers to my questions:\\ \ 1. Is the world analog or digital? \end{leftbar} digital  \begin{leftbar} 2. How long does the world exist?  \end{leftbar} analog since 1984, digital since 1999  \end{document}     This is what the above latex example looks like.    I also saw  but I do not want to use &gt; or colors. My settings are inspired by this  and this .
103588
In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:  "[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]"   Is there a way to get similar behavior in Python? I implemented a __str__() method in my class, but when I print out a list of objects, using:  print 'my list is %s'%(list)   it looks something like this:  [&lt;__main__.cell instance at 0x2a955e95f0&gt;, &lt;__main__.cell instance at 0x2a955e9638&gt;, &lt;__main__.cell instance at 0x2a955e9680&gt;]   how can I get python to call my __str__ automatically for each element inside the list (or dict for that matter)?
120233
I would like to be able to pass aarguments to operators that I am calling from panels/buttons but I do not know how to do that. At the moment I use "global" variables but they tend to make the code a bit like a puzzle since I need to constantly update them.  See the code below, in that example I would like to pass an argument (like ARG) to "object.simple_operator" when the button is clicked.  import bpy     def DO_SOMETHING(arg):      print(arg)  return  class SimpleOperator(bpy.types.Operator):     """Tooltip"""     bl_idname = "object.simple_operator"     bl_label = "Simple Object Operator"      @classmethod     def poll(cls, context):         return context.active_object is not None      def execute(self, context):         DO_SOMETHING(ARG)         return {'FINISHED'}    class MyPanel(bpy.types.Panel):      bl_label = "mypanel"     bl_idname = "OBJECT_PT_MyPanel"      def draw(self, context):          layout = self.layout          wm = context.window_manager          obj = context.object          row = layout.row()         row.operator('object.simple_operator')
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?