User Profile

Collapse

Profile Sidebar

Collapse
Glenton
Glenton
Last Activity: May 31 '16, 11:28 PM
Joined: Nov 15 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Hi Steve

    According to this:
    https://msdn.microsoft.com/en-us/lib...ffice.11).aspx

    you should be able to step through all the selected items with a for loop:

    Code:
    For Each vrtSelectedItem In .SelectedItems
    
                    'vrtSelectedItem is a String that contains the path of each selected item.
                    'You can use any file I/O functions that you want to
    ...
    See more | Go to post

    Leave a comment:


  • One way to get the base file name is to use the FileSystemObjec t. It might be a little more convenient that the fGetBaseFileNam e function. It uses Microsoft Scripting Runtime (Tools - References - Microsoft Scripting Runtime).

    Code snippets as follows:

    Code:
    Dim fso As New FileSystemObject  'Add Microsoft Scripting Runtime to work with this library (Tools - References - Microsoft Scripting Runtime)
       
    strSelectedFile
    ...
    See more | Go to post

    Leave a comment:


  • Glenton
    started a topic Google App Javascript Import of html

    Google App Javascript Import of html

    Hi.

    Firstly apologies, but I'm experimenting and hope my question makes some kind of sense!

    I am trying to write a script for a google spreadsheet, and would like to import some crypto code from elsewhere.

    The code I would like to use is here. The home page, showing the usage is here.

    I have written some code to test the principle:
    Code:
    function endecode(){
    
      var sheet=SpreadsheetApp.getActiveSheet();
    ...
    See more | Go to post

  • Glenton
    replied to How to access the values from a dictionary
    Weird question. You would get far better help if you actually asked the question properly.

    Typically the dictionary is assigned to a variable, and the values can be accessed through the key. In the case the values are lists, which in turn can be accessed through an index.

    Suppose the dictionary you give above was assigned to the variable weirdDict.

    Then
    Code:
    >>weirdDict[2][0]
    >>FACILITY
    ...
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to reading a column from text
    Hi

    We often like to see the code you've attempted so far, what results you've got and what you're looking for.

    However, the simple way to do this is to use regular expressions.

    For example:
    Code:
    import re
    myFile=open("input.txt")
    
    result={}   # dictionary for results  
    p=re.compile(r'(.*) (.*) (.*)')
    start=False
    for line in myFile:
        if not start: #continue
    ...
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to Counting words from text file
    Hi

    Do you have a seed list of countries that you are going to look for? Are you going to look for "USA", "United States", "US of A", "United States of America", "America" as separate items? If so, you need also to be cognisant that "America" would also be found when "United States of America" is found etc.

    There tends to be a lot of messy details with...
    See more | Go to post

    Leave a comment:


  • Often a good way to do it (depending what you're trying to achieve) is to create a dictionary before the loop and then use whatever loop variable you want as the key for the dictionary. This is generally better than using eval IMHO. You also don't need to have a string as the key but can have any immutable type Eg an integer or a tuple.
    See more | Go to post

    Leave a comment:


  • Alternatively you can do it without re
    Code:
    import re
    
    lines=open("input.txt","r")
    
    
    for line in lines:
        l1=line.replace(" ","").replace('"','').split(",")  #Remove the spaces from the line and separate on ,
        if len(l1)<2: continue   #to avoid lines that don't fit the general pattern
        l2=l1[0].split("(")
        l3=[l1[-2].replace(")","")]
    ...
    See more | Go to post

    Leave a comment:


  • Yes, re objects don't print well, I'm afraid.

    You need to use their attributes or methods. It can be a bit frustrating to debug and to understand. Try reading the docs link from my previous post. Good luck!
    See more | Go to post

    Leave a comment:


  • You can look here to get more details on how regular expressions work.

    I don't understand your statement "I tried to print but it only print address". What does this mean? The code should work to create the output that I gave.

    re.compile is to make a pattern that you can match some text against. In this case it looks for the following:
    ' "' is the start of the string

    ' *' is some...
    See more | Go to post

    Leave a comment:


  • Regular expressions are what you need. They take a bit of getting used to, but work brilliantly once you have the hang of it.

    You have a different number of variables in your input.txt file, so the below works with the first ones, which have the format you posted originally, but not with the latter ones:

    Code:
    import re
    
    lines=open("input.txt","r")
    
    p=re.compile('   " *(.*) \((.*),
    ...
    See more | Go to post

    Leave a comment:


  • The "print b," is to print b without going to a new line. It's to do the equivalent of printing a[0], a[1], a[2],... for as many as are needed.

    The "print" at the end is to make a new line.

    I was assuming your regular expression was working, but perhaps it isn't. I can't imaging that your split expression would work either.

    Perhaps you can explain the logic of what you're trying to achieve....
    See more | Go to post

    Leave a comment:


  • The easy way to do this more safely would be something like
    Code:
    import re
    lines=open("input.txt",'r').readlines()
     
    for line in lines:
        a=re.findall(r'\w+',line)
        print re.findall(r'\w+',line)
        #print a[0],a[1],a[2],a[3],a[4],a[5],a[6]
        for b in a:
            print b,
        print
    See more | Go to post

    Leave a comment:


  • Can you let us know what you mean by "does not work"? What's the error message? Does the prev_day need quotation marks?
    See more | Go to post

    Leave a comment:


  • This is done by setting a dialect in your csv writer. Dialect is an csv object and you can set the dialect.delimit er to '/t'.

    See here
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to please how to create a matrix in python??
    Incidentally numpy has a matrix object that does the above and also supports matrix operations
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to creating huge transition matrix
    Hi. Numpy and Scipy were created to handle n-dimensional arrays so 3 is certainly not a problem. It's very similar to matlab (except better IMHO).

    When you program in compiled languages like C or Java you get a huge performance benefit over higher level languages like python or perl. The flip side is that the actual coding is generally far simpler and more terse in python. Eg C may take 100th time to run but have triple the lines of...
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to splash screen problem
    Is it just the geometry you're struggling with?
    If m,n is width, length of image and
    M,N is width,length of canvas, then corner coordinates will be
    ((M-m)/2,(N-n)/2)
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to IndexError: list index out of range
    Good point BVDET.
    If you add in a line like this:
    Code:
    if len(student[i])==0: continue
    after the for statement and before the if statement you'll be able to skip empty records. Of course it would be better not to have empty records but it depends how things are set up.

    Another thing that is quite common is to set up a class object for student instead of a list. A list is unwieldy because you need to keep track of what...
    See more | Go to post

    Leave a comment:


  • Glenton
    replied to IndexError: list index out of range
    Can you post the error and perhaps a simple example of the code failing.
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...