Search Results

Search found 5101 results on 205 pages for 'expression trees'.

Page 159/205 | < Previous Page | 155 156 157 158 159 160 161 162 163 164 165 166  | Next Page >

  • Python text file processing speed issues

    - by Anonymouslemming
    Hi all, I'm having a problem with processing a largeish file in Python. All I'm doing is f = gzip.open(pathToLog, 'r') for line in f: counter = counter + 1 if (counter % 1000000 == 0): print counter f.close This takes around 10m25s just to open the file, read the lines and increment this counter. In perl, dealing with the same file and doing quite a bit more (some regular expression stuff), the whole process takes around 1m17s. Perl Code: open(LOG, "/bin/zcat $logfile |") or die "Cannot read $logfile: $!\n"; while (<LOG>) { if (m/.*\[svc-\w+\].*login result: Successful\.$/) { $_ =~ s/some regex here/$1,$2,$3,$4/; push @an_array, $_ } } close LOG; Can anyone advise what I can do to make the Python solution run at a similar speed to the Perl solution? I've tried just uncompressing the file and dealing with it using open instead of gzip.open, but that made a very small difference to the overall time.

    Read the article

  • Show me some cool python list comprehensions

    - by christangrant
    One of the major strengths of python and a few other (functional) programming languages are the list comprehension. They allow programmers to write complex expressions in 1 line. They may be confusing at first but if one gets used to the syntax, it is much better than nested complicated for loops. With that said, please share with me some of the coolest uses of list comprehensions. (By cool, I just mean useful) It could be for some programming contest, or a production system. For example: To do the transpose of a matrix mat >>> mat = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9], ... ] >>> [[row[i] for row in mat] for i in [0, 1, 2]] [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Please include a description of the expression and where it was used (if possible).

    Read the article

  • WPF: Custom control that binds its content to a label

    - by nialsh
    I want to write a custom control that's used like this: <HorizontalTick>Some string</HorizontalTick> It should render like this: -- Some string ------------------------------------------- Here's my code: <UserControl x:Class="WeatherDownloadDisplay.View.HorizontalTick" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignWidth="348" Name="controlRoot"> <DockPanel LastChildFill="True"> <UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1" Width="10"/> <Label Content="???" /> <UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1"/> </DockPanel> It works except for the label binding. Can someone help me fill in the question marks? I thought about using a ContentPresenter but it seems like an inline binding would be best. -Neal

    Read the article

  • Accessing 'data' argument of with() function?

    - by Ken Williams
    Is it possible, in the expr expression of the with() function, to access the data argument directly? Here's what I mean conceptually: > print(df) result qid f1 f2 f3 -1 1 0.0000 0.1253 0.0000 -1 1 0.0098 0.0000 0.0000 1 1 0.0000 0.0000 0.1941 -1 2 0.0000 0.2863 0.0948 1 2 0.0000 0.0000 0.0000 1 2 0.0000 0.7282 0.9087 > with(df, subset(.data, select=f1:f3)) # Doesn't work Of course the above example is kind of silly, but it would be handy for things like this: with(subset(df, f2>0), foo(qid, vars=subset(.data, select=f1:f3))) I tried to poke around with environment() and parent.frame() etc., but didn't come up with anything that worked. Maybe this is really a question about eval(), since that's how with.default() is implemented.

    Read the article

  • Is there a Windows utility that will let me do multiple programmatic find/replaces on text that I cu

    - by billmaya
    I've inherited some C# code that contains about a thousand lines of source that I need to modify, transforming it from this: newDataRow["to_dir"] = comboBox108.Text; To this: assetAttributes.Add("to_dir", comboBox108.Text); The lines occur in various places throughout the application in groups of 40 or 50. Modifying each line by hand in Visual Studio 2008 can be done but it's labor intensive and prone to errors. Is there a Windows utility out there that will let me cut and paste groups of code into it and then run some sort of reg-ex expression to transform the individual lines one-by-one? I'd also be willing to use some sort of VS 2008 add-in that performed the same set of reg-ex operations against a selection of code. Thanks in advance.

    Read the article

  • Let and construct versus let in sequence

    - by Stringer
    Consider this OCaml code: let coupe_inter i j cases = let lcases = Array.length cases in let low,_,_ = cases.(i) and _,high,_ = cases.(j) in low,high, Array.sub cases i (j-i+1), case_append (Array.sub cases 0 i) (Array.sub cases (j+1) (lcases-(j+1))) Why the expression let ... and ... in is used in place of a let ... in let ... in sequence (like F# force you to do)? This construct seems quite frequent in OCaml code. Thanks!

    Read the article

  • Convert Json date string to JavaScript date object

    - by dagda1
    Hi, I have the following JSON object which has a date field in the following format: { "AlertDate": "\/Date(1277334000000+0100)\/", "Progress": 1, "ReviewPeriod": 12 } I want to write a regular expression or a function to convert it to a javascript object so that it is in the form: { "AlertDate": "AlertDate":new Date(1277334000000), "Progress": 1, "ReviewPeriod": 12 } The above date format fails validation in the JQuery parseJSON method. I would like to convert the 1277334000000+0100 into the correct number of milliseconds to create the correct date when eval is called after validation. Can anyone help me out with a good approach to solving this? Cheers Paul

    Read the article

  • How can I check the type of an object against a list of types?

    - by RookieRick
    Given a collection IEnumerable<Type> supportedTypes What's the best way to check whether a given object is one of those types (or a derived type)? My first instinct was to do something like: // object target is a parameter passed to the method in which I'm doing this. if (supportedTypes.Count( supportedType => target is supportedType ) > 0) { // Yay my object is of a supported type!!! } ..but that doesn't seem to be working. Can I not use the "is" keyword in a lambda expression like this?

    Read the article

  • How do I insert data into a object relational table with multiple ref in the schema.

    - by Yiling
    I have a table with a schema of Table(number, ref, ref, varchar2, varchar2,...). How would I insert a row of data into this table? When I do: "insert into table values (1, select ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... from plaintiff p, defendant d where p.name='name1' and d.name='name2');" I get a "missing expression" error. If I do: "insert into table 1, select ref(p), ref(d), ... from plaintiff p, defendant where p.name=...;" I get a "missing keyword VALUES" error.

    Read the article

  • arrays declaration and addressing

    - by avinash
    I have a few straightforward questions:- Is the following correct according to a normal c++ compiler? int arr[3][4]; void func(int *a, int m, int n) { int i,j; cin>>i>>j; cout<< a[i*n + j]; //is this way of addressing correct provided 0<=i<m and 0<=j<n } int main() { func((int*)arr, 3,4); } If the bounds of an array strictly has to be a constant expression, why doesn't the following generate compiler errors? int func(int m, int n) { int arr[m][n]; //m and n are not known until run time }

    Read the article

  • F# operator over-loading question

    - by jyoung
    The following code fails in 'Evaluate' with: "This expression was expected to have type Complex but here has type double list" Am I breaking some rule on operator over-loading on '(+)'? Things are OK if I change '(+)' to 'Add'. open Microsoft.FSharp.Math /// real power series [kn; ...; k0] => kn*S^n + ... + k0*S^0 type Powers = double List let (+) (ls:Powers) (rs:Powers) = let rec AddReversed (ls:Powers) (rs:Powers) = match ( ls, rs ) with | ( l::ltail, r::rtail ) -> ( l + r ) :: AddReversed ltail rtail | ([], _) -> rs | (_, []) -> ls ( AddReversed ( ls |> List.rev ) ( rs |> List.rev) ) |> List.rev let Evaluate (ks:Powers) ( value:Complex ) = ks |> List.fold (fun (acc:Complex) (k:double)-> acc * value + Complex.Create(k, 0.0) ) Complex.Zero

    Read the article

  • C# Regex: only letters followed by an optional .

    - by TheDude
    Hello, I am looking for a way to get words out of a sentence. I am pretty far with the following expression: \b([a-zA-Z]+?)\b but there are some occurrences that it counts a word when I want it not to. E.g a word followed by more than one period like "text..". So, in my regex I want to have the period to be at the end of a word zero or one time. Inserting .? did not do the trick, and variations on this have not yielded anything fruitful either. Hope someone can help!

    Read the article

  • How to ORDER BY non-column field?

    - by Phil Bolduc
    I am trying to create an Entity SQL that is a union of two sub-queries. (SELECT VALUE DISTINCT ROW(e.ColumnA, e.ColumnB, 1 AS Rank) FROM Context.Entity AS E WHERE ...) UNION ALL (SELECT VALUE DISTINCT ROW(e.ColumnA, e.ColumnB, 2 AS Rank) FROM Context.Entity AS E WHERE ...) ORDER BY *??* LIMIT 50 I have tried: ORDER BY Rank and ORDER BY e.Rank but I keep getting: System.Data.EntitySqlException: The query syntax is not valid. Near keyword 'ORDER' I do not think it is a problem with the Rank column. I do think it is how I am trying to apply an order by to two different esql statements joined by union all. Could someone suggest: How to apply a ORDER BY to this kind of UNION/UNION ALL statment How to order by the non-entity column expression. Thanks.

    Read the article

  • How to extract object reference from property access lamda

    - by Jim C
    Here's a follow-up question to http://stackoverflow.com/questions/2820660/get-name-of-property-as-a-string. Given a method Foo (error checking omitted for brevity): // Example usage: Foo(() => SomeClass.SomeProperty) // Example usage: Foo(() => someObject.SomeProperty) void Foo(Expression<Func<T>> propertyLambda) { var me = propertyLambda.Body as MemberExpression; var pi = me.Member as PropertyInfo; bool propertyIsStatic = pi.GetGetMethod().IsStatic; object owner = propertyIsStatic ? me.Member.DeclaringType : ???; ... // Execute property access object value = pi.GetValue(owner, null); } I've got the static property case working but don't know how to get a reference to someObject in the instance property case. Thanks in advance.

    Read the article

  • What is wrong with my SQL syntax for an UPDATE with a JOIN?

    - by Phil H
    I have two tables, related by a common key. So TableA has key AID and value Name and TableB has keys AID, BID and values Name, Value: AID Name 74 Alpha AID BID Name Value 74 4 Beta Brilliance I would like to update the TableB Value here from Brilliance to Barmy, using just the Name fields. I thought I could do it via an UPDATE containing a JOIN, but Access (I know...) is complaining with 'Syntax error (missing operator) in query expression ' and then everything from 'Barmy' here: UPDATE tB SET tB.BValue='Barmy' FROM TableB tB INNER JOIN TableA tA ON tB.AID=tA.AID WHERE tB.Name='Beta' AND tA.Name='Alpha'; What is my heinous crime? Or is it just Access not conforming?

    Read the article

  • Regexp in iOS to find comments

    - by SteveDolphin23
    I am trying to find and process 'java-style' comments within a string in objective-C. I have a few regex snippets which almost work but I am stuck on one hurdle: different options seem to make the different styles work. For example, I am using this to match: NSArray* matches = [[NSRegularExpression regularExpressionWithPattern:expression options:NSRegularExpressionAnchorsMatchLines error:nil] matchesInString:string options:0 range:searchRange]; The options here allow me successfully find and process single line comments (//) but not multiline (/* */), if I change the option to NSRegularExpressionDotMatchesLineSeparators then I can make multiline work fine but I can't find the 'end' of a single line comment. I suppose really I need dot-matches-line-separators but I need a better way of finding the end of a single line comment? The regexp I have so far are: @"/\\*.*?\\*/" @"//.*$" it's clear to see if dot matches a line separator then the second one (single line) never 'finishes' but how do I fix this? I found some suggestions for single line that were more like: @"(\/\/[^"\n\r]*(?:"[^"\n\r]*"[^"\n\r]*)*[\r\n])" But that doesn't' seem to work at all! Thanks in advance for any pointers.

    Read the article

  • Using Regular Expressions

    - by bebeTech
    I am having problems trying to use the regular expression that I used in JavaScript. On a web page, you may have: <b>Renewal Date:</b> 03 May 2010</td> I just want to be able to pull out the 03 May 2010, remembering that a webpage has more than just the above content. The way I currently perform this using JavaScript is: DateStr = /<b>Renewal Date:<\/b>(.+?)<\/td>/.exec(returnedHTMLPage); I tried to follow some tutorials on java.util.regex.Pattern and java.util.regex.Matcher with no luck. I can't seem to be able to translate (.+?) into something they can understand?? thanks, Noeneel

    Read the article

  • Changing size of a dynamically allocated matrix

    - by user1309174
    Trying to re-size the shape matrix dynamically. This is part of a drawing program where _capacity is the number of shapes drawn on a frame. Get the error in new Shape about _capacity saying expression needs to have a constant value. void ShapeStore::Grow(int minimumCapacity) { _capacity = max (minimumCapacity, 2 * _capacity); if (_capacity) { Shape ***newData = new Shape[_frames][_capacity]; //figure out this int i; for (int k = 0; k < _frames; k++) for (i=0;i<_count;i++) newData[k][i] = _data[k][i]; delete [] _data; _data = newData; } //*/ }

    Read the article

  • Unrecognized option: -o Could not create the Java virtual machine.

    - by Kerubu
    I've got an unusual build error when using Buildroot to create an image for my Phidget SBC. It's unusual because it occurs ONLY on my development laptop and NOT on my general use laptop even though I am using EXACTLY the same Builroot environment as published by Phidgets themselves. When I try to create my Buildroot image I get the following error when it attempts to compile GNU classpath: Making all in tools make[2]: Entering directory `/home/xxxx/buildroot_phidgetsbc/buildroot-phidgetsbc_1.0.4.20111028/output/build/classpath-0.98/tools' /bin/mkdir -p classes asm /bin/mkdir -p ../tools/generated/gnu/classpath/tools/gjdoc/expr java -classpath antlr.Tool -o ../tools/generated/gnu/classpath/tools/gjdoc/expr/ \ ./gnu/classpath/tools/gjdoc/expr/java-expression.g Unrecognized option: -o Could not create the Java virtual machine. make[2]: *** [tools.zip] Error 1 The only difference I can possibly thing of is the different Linux (Ubuntu) versions I am using on each laptop. Also I cannot find a -o option documented for Java and don't understand why it works on one laptop but not the other. Any suggestions would be helpful.

    Read the article

  • Is it possible to define XML schemata with node names specified via regular expressions?

    - by MartyIX
    Hello, I know it is probably a question against XML philosophy but still is it possible to define schemata for XML like this: <Root> <arbitrary-name-of-node> <Name></Name> <Position></Position> <!-- ... --> </arbitrary-name-of-node> <arbitrary-name-of-node> <Name></Name> <Position></Position> <!-- ... --> </arbitrary-name-of-node> </Root> where arbitrary-name-of-node matches regular expression [a-zA-Z0-9]? Thanks for an answer!

    Read the article

  • question in sql server 2005 Proc

    - by bassam
    i have this Proc CREATE Proc [dbo].Salse_Ditail -- Add the parameters for the stored procedure here @Report_Form varchar(1) , @DateFrom datetime , @DateTo datetime , @COMPANYID varchar(3), @All varchar(1) , @All1 varchar(1) , @All2 varchar(1) , @All3 varchar(1) , @All4 varchar(1) , @All5 varchar(1) , @Sector varchar(10), @Report_Parameter nvarchar(max) as BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. DECLARE @STRWhere nvarchar(max) IF @All5=0 AND @All4=0 AND @All3=0 AND @All2=0 AND @All1=0 and @All=1 set @STRWhere= N'and Sector_id = @Sector' if @Report_Form =1 or @Report_Form =3 or @Report_Form =4 SELECT RETURNREASONCODEID, SITE,SITE_NAME,Factory_id,Factory_Name,Sector_id,sector_name,Customer_name, Customer_id,ITEMID,ITEMNAME,SALESMANID,SALESMAN_NAME,Net_Qty,Net_Salse,Gross_Sales,Gross_Qty, NETWEIGHT_Gross,NETWEIGHT_salse_Gross,NETWEIGHT_NET,NETWEIGHT_salse_NET,Return_Sales,Free_Good, CollectionAmount FROM hal_bas_new_rep WHERE DATAAREAID =@COMPANYID AND INVOICEDATE >= @DateFrom AND INVOICEDATE <= @DateTo and Report_Activti = @Report_Form if @Report_Form =2 SELECT RETURNREASONCODEID , RETURNREASONDESC, SITE , SITE_NAME , Factory_id , Factory_Name , Sector_id , sector_name , Customer_name , Customer_id , ITEMID , ITEMNAME , SALESMANID , SALESMAN_NAME , Return_Sales FROM dbo.hal_bas_new_rep WHERE DATAAREAID =@COMPANYID AND INVOICEDATE >= @DateFrom AND INVOICEDATE <= @DateTo and Report_Activti = @Report_Form and RETURNREASONCODEID in ( SELECT Val FROM dbo.fn_String_To_Table(@Report_Parameter,',',1) ) /* @STRWhere question how i can but the virble here */ end GO i want to but virble put a variable under where Expression and from this function buc I have many function i want to add if any one have answer pls send me

    Read the article

  • using key/value collection in session

    - by jumpdart
    Question: What is a good datatype to keep in session for a large collection of keys and values to frequently reference and update? Application: Updating an old .NET web app with a million pages and grids to have all the grids maintain their sort. They currently access helper code to format themselves graphically on load and on sort. I figured I could add to that code to check for a key based on the page and grid id in a collection in session to see if it has a previous expression on load. and the on sort update/add its appropriate item in the collection. Thoughts? Dictionary vs NameValueCollection

    Read the article

  • Is possible to set generic type by another class?

    - by Soul_Master
    I use ASP.NET MVC for serving web application and I want to create something like the following code. <% using(HTML.Form(Model)) { %> <% HTML.CreateTextBox('txt1', x => x.Property1); <% } From the above code, Form extension method will receive object that represent type of current Model object in current View page. Next, CreateTextBox method will receive type from Form method and I can bind textbox to some property of this model. Update 1 The following code is code of CreateTextBox method that will create instance of TextBox class. public static CreateTextBox(string value, Expression<Func<object>> bindedProperty) { // T should be receive from HTML.Form method or class return new TextBox<T>(value); } Is it possible to creating some code that doing something like the above code? Thanks,

    Read the article

  • Java Sql Udate error, data type missmatch

    - by codo
    I have created a table in ms access. I have set the data type of ID to Auto Number in MS-access. In java when I try to update a record. the netBeans IDE gives me the error of " data type missmatch in criteria expression". But when I changed the ID number that was not in the table already it works well. The code is below. String sql = "Update table1 set price ='" + txtPrice.getText() + "', quantity='" + txtQuantity.getText() + "', description='" + txtDescription.getText() + "' where id= " + txtid.getText() + ""; try { pst = conn.prepareStatement(sql); pst.executeUpdate(); JOptionPane.showMessageDialog(null, "Updated"); UpdateJTable(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); }

    Read the article

  • (.*) instead of (.*?)

    - by EBAGHAKI
    Suppose we have this html content, and we are willing to get Content1, Content2,.. with regular expression. <li>Content1</li> <li>Content2</li> <li>Content3</li> <li>Content4</li> If I use the line below preg_match_all('/<li>(.*)<\/li>/', $text, $result); i will get an array with a single row containing: Content1</li> <li>Content2</li> <li>Content3</li> <li>Content4 And by using this code: preg_match_all('/<li>(.*?)<\/li>/', $text, $result); i will get an array with 4 row containing Content1, Content2, ... Why (.*) is not working since it means match any character zero or more times

    Read the article

< Previous Page | 155 156 157 158 159 160 161 162 163 164 165 166  | Next Page >